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
180d33ee
Unverified
Commit
180d33ee
authored
Jul 11, 2023
by
OptimismBot
Committed by
GitHub
Jul 11, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6255 from ethereum-optimism/refcell/abitest/challenger
feat(op-challenger): Manual ABI Packing Tests
parents
98aadbba
900053ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
+74
-0
abi_test.go
op-challenger/fault/abi_test.go
+74
-0
No files found.
op-challenger/fault/abi_test.go
0 → 100644
View file @
180d33ee
package
fault
import
(
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
)
// setupFaultDisputeGame deploys the FaultDisputeGame contract to a simulated backend
func
setupFaultDisputeGame
()
(
common
.
Address
,
*
bind
.
TransactOpts
,
*
backends
.
SimulatedBackend
,
*
bindings
.
FaultDisputeGame
,
error
)
{
privateKey
,
err
:=
crypto
.
GenerateKey
()
from
:=
crypto
.
PubkeyToAddress
(
privateKey
.
PublicKey
)
if
err
!=
nil
{
return
common
.
Address
{},
nil
,
nil
,
nil
,
err
}
opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
privateKey
,
big
.
NewInt
(
1337
))
if
err
!=
nil
{
return
common
.
Address
{},
nil
,
nil
,
nil
,
err
}
backend
:=
backends
.
NewSimulatedBackend
(
core
.
GenesisAlloc
{
from
:
{
Balance
:
big
.
NewInt
(
params
.
Ether
)}},
50
_000_000
)
_
,
_
,
contract
,
err
:=
bindings
.
DeployFaultDisputeGame
(
opts
,
backend
,
[
32
]
byte
{
0x01
},
big
.
NewInt
(
15
),
common
.
Address
{
0xdd
},
)
if
err
!=
nil
{
return
common
.
Address
{},
nil
,
nil
,
nil
,
err
}
return
from
,
opts
,
backend
,
contract
,
nil
}
// TestBuildFaultDefendData ensures that the manual ABI packing is the same as going through the bound contract.
func
TestBuildFaultDefendData
(
t
*
testing
.
T
)
{
_
,
opts
,
_
,
contract
,
err
:=
setupFaultDisputeGame
()
require
.
NoError
(
t
,
err
)
responder
,
_
:=
newTestFaultResponder
(
t
,
false
)
data
,
err
:=
responder
.
buildFaultDefendData
(
1
,
[
32
]
byte
{
0x02
,
0x03
})
require
.
NoError
(
t
,
err
)
opts
.
GasLimit
=
100
_000
tx
,
err
:=
contract
.
Defend
(
opts
,
big
.
NewInt
(
1
),
[
32
]
byte
{
0x02
,
0x03
})
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
data
,
tx
.
Data
())
}
// TestBuildFaultAttackData ensures that the manual ABI packing is the same as going through the bound contract.
func
TestBuildFaultAttackData
(
t
*
testing
.
T
)
{
_
,
opts
,
_
,
contract
,
err
:=
setupFaultDisputeGame
()
require
.
NoError
(
t
,
err
)
responder
,
_
:=
newTestFaultResponder
(
t
,
false
)
data
,
err
:=
responder
.
buildFaultAttackData
(
1
,
[
32
]
byte
{
0x02
,
0x03
})
require
.
NoError
(
t
,
err
)
opts
.
GasLimit
=
100
_000
tx
,
err
:=
contract
.
Attack
(
opts
,
big
.
NewInt
(
1
),
[
32
]
byte
{
0x02
,
0x03
})
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
data
,
tx
.
Data
())
}
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