Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
bd80e581
Unverified
Commit
bd80e581
authored
Apr 25, 2024
by
Adrian Sutton
Committed by
GitHub
Apr 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: Read created game address from receipt (#10277)
Extracts the game creation logic into reusable code.
parent
b4df5c65
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
275 additions
and
17 deletions
+275
-17
create_game.go
op-challenger/cmd/create_game.go
+5
-16
list_games.go
op-challenger/cmd/list_games.go
+1
-1
gamefactory.go
op-challenger/game/fault/contracts/gamefactory.go
+32
-0
gamefactory_test.go
op-challenger/game/fault/contracts/gamefactory_test.go
+68
-0
create_game.go
op-challenger/tools/create_game.go
+44
-0
bound.go
op-service/sources/batching/bound.go
+40
-0
bound_test.go
op-service/sources/batching/bound_test.go
+85
-0
No files found.
op-challenger/cmd/create_game.go
View file @
bd80e581
package
main
package
main
import
(
import
(
"context"
"fmt"
"fmt"
"github.com/ethereum-optimism/optimism/op-challenger/config"
"github.com/ethereum-optimism/optimism/op-challenger/config"
"github.com/ethereum-optimism/optimism/op-challenger/flags"
"github.com/ethereum-optimism/optimism/op-challenger/flags"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
"github.com/ethereum-optimism/optimism/op-challenger/tools"
opservice
"github.com/ethereum-optimism/optimism/op-service"
opservice
"github.com/ethereum-optimism/optimism/op-service"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
...
@@ -43,23 +43,12 @@ func CreateGame(ctx *cli.Context) error {
...
@@ -43,23 +43,12 @@ func CreateGame(ctx *cli.Context) error {
return
fmt
.
Errorf
(
"failed to create dispute game factory bindings: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to create dispute game factory bindings: %w"
,
err
)
}
}
txCandidate
,
err
:=
contract
.
CreateTx
(
ctx
.
Context
,
uint32
(
traceType
),
outputRoot
,
l2BlockNum
)
creator
:=
tools
.
NewGameCreator
(
contract
,
txMgr
)
gameAddr
,
err
:=
creator
.
CreateGame
(
ctx
.
Context
,
outputRoot
,
traceType
,
l2BlockNum
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to create
tx
: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to create
game
: %w"
,
err
)
}
}
fmt
.
Printf
(
"Fetched Game Address: %s
\n
"
,
gameAddr
.
String
())
rct
,
err
:=
txMgr
.
Send
(
context
.
Background
(),
txCandidate
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to send tx: %w"
,
err
)
}
fmt
.
Printf
(
"Sent create transaction with status %v, tx_hash: %s
\n
"
,
rct
.
Status
,
rct
.
TxHash
.
String
())
fetchedGameAddr
,
err
:=
contract
.
GetGameFromParameters
(
context
.
Background
(),
uint32
(
traceType
),
outputRoot
,
l2BlockNum
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to call games: %w"
,
err
)
}
fmt
.
Printf
(
"Fetched Game Address: %s
\n
"
,
fetchedGameAddr
.
String
())
return
nil
return
nil
}
}
...
...
op-challenger/cmd/list_games.go
View file @
bd80e581
...
@@ -94,7 +94,7 @@ func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contr
...
@@ -94,7 +94,7 @@ func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contr
fmt
.
Printf
(
lineFormat
,
"Idx"
,
"Game"
,
"Type"
,
"Created (Local)"
,
"L2 Block"
,
"Output Root"
,
"Claims"
,
"Status"
)
fmt
.
Printf
(
lineFormat
,
"Idx"
,
"Game"
,
"Type"
,
"Created (Local)"
,
"L2 Block"
,
"Output Root"
,
"Claims"
,
"Status"
)
for
idx
,
game
:=
range
infos
{
for
idx
,
game
:=
range
infos
{
if
game
.
err
!=
nil
{
if
game
.
err
!=
nil
{
return
err
return
game
.
err
}
}
created
:=
time
.
Unix
(
int64
(
game
.
Timestamp
),
0
)
.
Format
(
time
.
DateTime
)
created
:=
time
.
Unix
(
int64
(
game
.
Timestamp
),
0
)
.
Format
(
time
.
DateTime
)
fmt
.
Printf
(
lineFormat
,
fmt
.
Printf
(
lineFormat
,
...
...
op-challenger/game/fault/contracts/gamefactory.go
View file @
bd80e581
...
@@ -2,6 +2,7 @@ package contracts
...
@@ -2,6 +2,7 @@ package contracts
import
(
import
(
"context"
"context"
"errors"
"fmt"
"fmt"
"math/big"
"math/big"
...
@@ -11,7 +12,9 @@ import (
...
@@ -11,7 +12,9 @@ import (
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
ethTypes
"github.com/ethereum/go-ethereum/core/types"
)
)
const
(
const
(
...
@@ -21,12 +24,19 @@ const (
...
@@ -21,12 +24,19 @@ const (
methodInitBonds
=
"initBonds"
methodInitBonds
=
"initBonds"
methodCreateGame
=
"create"
methodCreateGame
=
"create"
methodGames
=
"games"
methodGames
=
"games"
eventDisputeGameCreated
=
"DisputeGameCreated"
)
var
(
ErrEventNotFound
=
errors
.
New
(
"event not found"
)
)
)
type
DisputeGameFactoryContract
struct
{
type
DisputeGameFactoryContract
struct
{
metrics
metrics
.
ContractMetricer
metrics
metrics
.
ContractMetricer
multiCaller
*
batching
.
MultiCaller
multiCaller
*
batching
.
MultiCaller
contract
*
batching
.
BoundContract
contract
*
batching
.
BoundContract
abi
*
abi
.
ABI
}
}
func
NewDisputeGameFactoryContract
(
m
metrics
.
ContractMetricer
,
addr
common
.
Address
,
caller
*
batching
.
MultiCaller
)
*
DisputeGameFactoryContract
{
func
NewDisputeGameFactoryContract
(
m
metrics
.
ContractMetricer
,
addr
common
.
Address
,
caller
*
batching
.
MultiCaller
)
*
DisputeGameFactoryContract
{
...
@@ -35,6 +45,7 @@ func NewDisputeGameFactoryContract(m metrics.ContractMetricer, addr common.Addre
...
@@ -35,6 +45,7 @@ func NewDisputeGameFactoryContract(m metrics.ContractMetricer, addr common.Addre
metrics
:
m
,
metrics
:
m
,
multiCaller
:
caller
,
multiCaller
:
caller
,
contract
:
batching
.
NewBoundContract
(
factoryAbi
,
addr
),
contract
:
batching
.
NewBoundContract
(
factoryAbi
,
addr
),
abi
:
factoryAbi
,
}
}
}
}
...
@@ -157,6 +168,27 @@ func (f *DisputeGameFactoryContract) CreateTx(ctx context.Context, traceType uin
...
@@ -157,6 +168,27 @@ func (f *DisputeGameFactoryContract) CreateTx(ctx context.Context, traceType uin
return
candidate
,
err
return
candidate
,
err
}
}
func
(
f
*
DisputeGameFactoryContract
)
DecodeDisputeGameCreatedLog
(
rcpt
*
ethTypes
.
Receipt
)
(
common
.
Address
,
uint32
,
common
.
Hash
,
error
)
{
for
_
,
log
:=
range
rcpt
.
Logs
{
if
log
.
Address
!=
f
.
contract
.
Addr
()
{
// Not from this contract
continue
}
name
,
result
,
err
:=
f
.
contract
.
DecodeEvent
(
log
)
if
err
!=
nil
{
// Not a valid event
continue
}
if
name
!=
eventDisputeGameCreated
{
// Not the event we're looking for
continue
}
return
result
.
GetAddress
(
0
),
result
.
GetUint32
(
1
),
result
.
GetHash
(
2
),
nil
}
return
common
.
Address
{},
0
,
common
.
Hash
{},
fmt
.
Errorf
(
"%w: %v"
,
ErrEventNotFound
,
eventDisputeGameCreated
)
}
func
(
f
*
DisputeGameFactoryContract
)
decodeGame
(
result
*
batching
.
CallResult
)
types
.
GameMetadata
{
func
(
f
*
DisputeGameFactoryContract
)
decodeGame
(
result
*
batching
.
CallResult
)
types
.
GameMetadata
{
gameType
:=
result
.
GetUint32
(
0
)
gameType
:=
result
.
GetUint32
(
0
)
timestamp
:=
result
.
GetUint64
(
1
)
timestamp
:=
result
.
GetUint64
(
1
)
...
...
op-challenger/game/fault/contracts/gamefactory_test.go
View file @
bd80e581
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
batchingTest
"github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
batchingTest
"github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
ethTypes
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
...
@@ -195,6 +196,73 @@ func TestGetGameImpl(t *testing.T) {
...
@@ -195,6 +196,73 @@ func TestGetGameImpl(t *testing.T) {
require
.
Equal
(
t
,
gameImplAddr
,
actual
)
require
.
Equal
(
t
,
gameImplAddr
,
actual
)
}
}
func
TestDecodeDisputeGameCreatedLog
(
t
*
testing
.
T
)
{
_
,
factory
:=
setupDisputeGameFactoryTest
(
t
)
fdgAbi
:=
snapshots
.
LoadDisputeGameFactoryABI
()
eventAbi
:=
fdgAbi
.
Events
[
eventDisputeGameCreated
]
gameAddr
:=
common
.
Address
{
0x11
}
gameType
:=
uint32
(
4
)
rootClaim
:=
common
.
Hash
{
0xaa
,
0xbb
,
0xcc
}
createValidReceipt
:=
func
()
*
ethTypes
.
Receipt
{
return
&
ethTypes
.
Receipt
{
Status
:
ethTypes
.
ReceiptStatusSuccessful
,
ContractAddress
:
fdgAddr
,
Logs
:
[]
*
ethTypes
.
Log
{
{
Address
:
fdgAddr
,
Topics
:
[]
common
.
Hash
{
eventAbi
.
ID
,
common
.
BytesToHash
(
gameAddr
.
Bytes
()),
common
.
BytesToHash
(
big
.
NewInt
(
int64
(
gameType
))
.
Bytes
()),
rootClaim
,
},
},
},
}
}
t
.
Run
(
"IgnoreIncorrectContract"
,
func
(
t
*
testing
.
T
)
{
rcpt
:=
createValidReceipt
()
rcpt
.
Logs
[
0
]
.
Address
=
common
.
Address
{
0xff
}
_
,
_
,
_
,
err
:=
factory
.
DecodeDisputeGameCreatedLog
(
rcpt
)
require
.
ErrorIs
(
t
,
err
,
ErrEventNotFound
)
})
t
.
Run
(
"IgnoreInvalidEvent"
,
func
(
t
*
testing
.
T
)
{
rcpt
:=
createValidReceipt
()
rcpt
.
Logs
[
0
]
.
Topics
=
rcpt
.
Logs
[
0
]
.
Topics
[
0
:
2
]
_
,
_
,
_
,
err
:=
factory
.
DecodeDisputeGameCreatedLog
(
rcpt
)
require
.
ErrorIs
(
t
,
err
,
ErrEventNotFound
)
})
t
.
Run
(
"IgnoreWrongEvent"
,
func
(
t
*
testing
.
T
)
{
rcpt
:=
createValidReceipt
()
rcpt
.
Logs
[
0
]
.
Topics
=
[]
common
.
Hash
{
fdgAbi
.
Events
[
"ImplementationSet"
]
.
ID
,
common
.
BytesToHash
(
common
.
Address
{
0x11
}
.
Bytes
()),
// Implementation addr
common
.
BytesToHash
(
big
.
NewInt
(
4
)
.
Bytes
()),
// Game type
}
// Check the log is a valid ImplementationSet
name
,
_
,
err
:=
factory
.
contract
.
DecodeEvent
(
rcpt
.
Logs
[
0
])
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"ImplementationSet"
,
name
)
_
,
_
,
_
,
err
=
factory
.
DecodeDisputeGameCreatedLog
(
rcpt
)
require
.
ErrorIs
(
t
,
err
,
ErrEventNotFound
)
})
t
.
Run
(
"ValidEvent"
,
func
(
t
*
testing
.
T
)
{
rcpt
:=
createValidReceipt
()
actualGameAddr
,
actualGameType
,
actualRootClaim
,
err
:=
factory
.
DecodeDisputeGameCreatedLog
(
rcpt
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
gameAddr
,
actualGameAddr
)
require
.
Equal
(
t
,
gameType
,
actualGameType
)
require
.
Equal
(
t
,
rootClaim
,
actualRootClaim
)
})
}
func
expectGetGame
(
stubRpc
*
batchingTest
.
AbiBasedRpc
,
idx
int
,
blockHash
common
.
Hash
,
game
types
.
GameMetadata
)
{
func
expectGetGame
(
stubRpc
*
batchingTest
.
AbiBasedRpc
,
idx
int
,
blockHash
common
.
Hash
,
game
types
.
GameMetadata
)
{
stubRpc
.
SetResponse
(
stubRpc
.
SetResponse
(
factoryAddr
,
factoryAddr
,
...
...
op-challenger/tools/create_game.go
0 → 100644
View file @
bd80e581
package
tools
import
(
"context"
"fmt"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
type
GameCreator
struct
{
contract
*
contracts
.
DisputeGameFactoryContract
txMgr
txmgr
.
TxManager
}
func
NewGameCreator
(
contract
*
contracts
.
DisputeGameFactoryContract
,
txMgr
txmgr
.
TxManager
)
*
GameCreator
{
return
&
GameCreator
{
contract
:
contract
,
txMgr
:
txMgr
,
}
}
func
(
g
*
GameCreator
)
CreateGame
(
ctx
context
.
Context
,
outputRoot
common
.
Hash
,
traceType
uint64
,
l2BlockNum
uint64
)
(
common
.
Address
,
error
)
{
txCandidate
,
err
:=
g
.
contract
.
CreateTx
(
ctx
,
uint32
(
traceType
),
outputRoot
,
l2BlockNum
)
if
err
!=
nil
{
return
common
.
Address
{},
fmt
.
Errorf
(
"failed to create tx: %w"
,
err
)
}
rct
,
err
:=
g
.
txMgr
.
Send
(
ctx
,
txCandidate
)
if
err
!=
nil
{
return
common
.
Address
{},
fmt
.
Errorf
(
"failed to send tx: %w"
,
err
)
}
if
rct
.
Status
!=
types
.
ReceiptStatusSuccessful
{
return
common
.
Address
{},
fmt
.
Errorf
(
"game creation transaction (%v) reverted"
,
rct
.
TxHash
.
Hex
())
}
gameAddr
,
_
,
_
,
err
:=
g
.
contract
.
DecodeDisputeGameCreatedLog
(
rct
)
if
err
!=
nil
{
return
common
.
Address
{},
fmt
.
Errorf
(
"failed to decode game created: %w"
,
err
)
}
return
gameAddr
,
nil
}
op-service/sources/batching/bound.go
View file @
bd80e581
...
@@ -6,11 +6,14 @@ import (
...
@@ -6,11 +6,14 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
)
var
(
var
(
ErrUnknownMethod
=
errors
.
New
(
"unknown method"
)
ErrUnknownMethod
=
errors
.
New
(
"unknown method"
)
ErrInvalidCall
=
errors
.
New
(
"invalid call"
)
ErrInvalidCall
=
errors
.
New
(
"invalid call"
)
ErrUnknownEvent
=
errors
.
New
(
"unknown event"
)
ErrInvalidEvent
=
errors
.
New
(
"invalid event"
)
)
)
type
BoundContract
struct
{
type
BoundContract
struct
{
...
@@ -48,3 +51,40 @@ func (b *BoundContract) DecodeCall(data []byte) (string, *CallResult, error) {
...
@@ -48,3 +51,40 @@ func (b *BoundContract) DecodeCall(data []byte) (string, *CallResult, error) {
}
}
return
method
.
Name
,
&
CallResult
{
args
},
nil
return
method
.
Name
,
&
CallResult
{
args
},
nil
}
}
func
(
b
*
BoundContract
)
DecodeEvent
(
log
*
types
.
Log
)
(
string
,
*
CallResult
,
error
)
{
if
len
(
log
.
Topics
)
==
0
{
return
""
,
nil
,
ErrUnknownEvent
}
event
,
err
:=
b
.
abi
.
EventByID
(
log
.
Topics
[
0
])
if
err
!=
nil
{
return
""
,
nil
,
fmt
.
Errorf
(
"%w: %v"
,
ErrUnknownEvent
,
err
.
Error
())
}
argsMap
:=
make
(
map
[
string
]
interface
{})
var
indexed
abi
.
Arguments
for
_
,
arg
:=
range
event
.
Inputs
{
if
arg
.
Indexed
{
indexed
=
append
(
indexed
,
arg
)
}
}
if
err
:=
abi
.
ParseTopicsIntoMap
(
argsMap
,
indexed
,
log
.
Topics
[
1
:
]);
err
!=
nil
{
return
""
,
nil
,
fmt
.
Errorf
(
"%w indexed topics: %v"
,
ErrInvalidEvent
,
err
.
Error
())
}
nonIndexed
:=
event
.
Inputs
.
NonIndexed
()
if
len
(
nonIndexed
)
>
0
{
if
err
:=
nonIndexed
.
UnpackIntoMap
(
argsMap
,
log
.
Data
);
err
!=
nil
{
return
""
,
nil
,
fmt
.
Errorf
(
"%w non-indexed topics: %v"
,
ErrInvalidEvent
,
err
.
Error
())
}
}
args
:=
make
([]
interface
{},
0
,
len
(
event
.
Inputs
))
for
_
,
input
:=
range
event
.
Inputs
{
val
,
ok
:=
argsMap
[
input
.
Name
]
if
!
ok
{
return
""
,
nil
,
fmt
.
Errorf
(
"%w missing argument: %v"
,
ErrUnknownEvent
,
input
.
Name
)
}
args
=
append
(
args
,
val
)
}
return
event
.
Name
,
&
CallResult
{
args
},
nil
}
op-service/sources/batching/bound_test.go
View file @
bd80e581
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
...
@@ -51,3 +52,87 @@ func TestDecodeCall(t *testing.T) {
...
@@ -51,3 +52,87 @@ func TestDecodeCall(t *testing.T) {
require
.
Zero
(
t
,
amount
.
Cmp
(
args
.
GetBigInt
(
1
)))
require
.
Zero
(
t
,
amount
.
Cmp
(
args
.
GetBigInt
(
1
)))
})
})
}
}
func
TestDecodeEvent
(
t
*
testing
.
T
)
{
testAbi
,
err
:=
bindings
.
ERC20MetaData
.
GetAbi
()
require
.
NoError
(
t
,
err
)
// event Transfer(address indexed from, address indexed to, uint256 amount);
event
:=
testAbi
.
Events
[
"Transfer"
]
contract
:=
NewBoundContract
(
testAbi
,
common
.
Address
{
0xaa
})
t
.
Run
(
"NoTopics"
,
func
(
t
*
testing
.
T
)
{
log
:=
&
types
.
Log
{}
_
,
_
,
err
:=
contract
.
DecodeEvent
(
log
)
require
.
ErrorIs
(
t
,
err
,
ErrUnknownEvent
)
})
t
.
Run
(
"UnknownEvent"
,
func
(
t
*
testing
.
T
)
{
log
:=
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{{
0xaa
}},
}
_
,
_
,
err
:=
contract
.
DecodeEvent
(
log
)
require
.
ErrorIs
(
t
,
err
,
ErrUnknownEvent
)
})
t
.
Run
(
"InvalidTopics"
,
func
(
t
*
testing
.
T
)
{
amount
:=
big
.
NewInt
(
828274
)
data
,
err
:=
event
.
Inputs
.
NonIndexed
()
.
Pack
(
amount
)
require
.
NoError
(
t
,
err
)
log
:=
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{
event
.
ID
,
common
.
BytesToHash
(
common
.
Address
{
0xaa
}
.
Bytes
()),
// Missing topic for to indexed value
},
Data
:
data
,
}
_
,
_
,
err
=
contract
.
DecodeEvent
(
log
)
require
.
ErrorIs
(
t
,
err
,
ErrInvalidEvent
)
})
t
.
Run
(
"MissingData"
,
func
(
t
*
testing
.
T
)
{
log
:=
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{
event
.
ID
,
common
.
BytesToHash
(
common
.
Address
{
0xaa
}
.
Bytes
()),
common
.
BytesToHash
(
common
.
Address
{
0xbb
}
.
Bytes
()),
},
}
_
,
_
,
err
:=
contract
.
DecodeEvent
(
log
)
require
.
ErrorIs
(
t
,
err
,
ErrInvalidEvent
)
})
t
.
Run
(
"InvalidData"
,
func
(
t
*
testing
.
T
)
{
log
:=
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{
event
.
ID
,
common
.
BytesToHash
(
common
.
Address
{
0xaa
}
.
Bytes
()),
common
.
BytesToHash
(
common
.
Address
{
0xbb
}
.
Bytes
()),
},
Data
:
[]
byte
{
0xbb
,
0xcc
},
}
_
,
_
,
err
:=
contract
.
DecodeEvent
(
log
)
require
.
ErrorIs
(
t
,
err
,
ErrInvalidEvent
)
})
t
.
Run
(
"ValidEvent"
,
func
(
t
*
testing
.
T
)
{
amount
:=
big
.
NewInt
(
828274
)
data
,
err
:=
event
.
Inputs
.
NonIndexed
()
.
Pack
(
amount
)
require
.
NoError
(
t
,
err
)
log
:=
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{
event
.
ID
,
common
.
BytesToHash
(
common
.
Address
{
0xaa
}
.
Bytes
()),
common
.
BytesToHash
(
common
.
Address
{
0xbb
}
.
Bytes
()),
},
Data
:
data
,
}
name
,
result
,
err
:=
contract
.
DecodeEvent
(
log
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
name
,
event
.
Name
)
require
.
Equal
(
t
,
common
.
Address
{
0xaa
},
result
.
GetAddress
(
0
))
require
.
Equal
(
t
,
common
.
Address
{
0xbb
},
result
.
GetAddress
(
1
))
require
.
Zerof
(
t
,
amount
.
Cmp
(
result
.
GetBigInt
(
2
)),
"expected %v but got %v"
,
amount
,
result
.
GetBigInt
(
2
))
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment