Commit f56bc8cd authored by Adrian Sutton's avatar Adrian Sutton

challenger: Don't export the base dispute game contract.

parent 4c16e214
...@@ -29,7 +29,7 @@ const ( ...@@ -29,7 +29,7 @@ const (
methodVM = "VM" methodVM = "VM"
) )
type DisputeGameContract struct { type disputeGameContract struct {
multiCaller *batching.MultiCaller multiCaller *batching.MultiCaller
contract *batching.BoundContract contract *batching.BoundContract
} }
...@@ -55,7 +55,7 @@ func asProposal(p contractProposal) Proposal { ...@@ -55,7 +55,7 @@ func asProposal(p contractProposal) Proposal {
} }
} }
func (f *DisputeGameContract) GetGameDuration(ctx context.Context) (uint64, error) { func (f *disputeGameContract) GetGameDuration(ctx context.Context) (uint64, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodGameDuration)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodGameDuration))
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to fetch game duration: %w", err) return 0, fmt.Errorf("failed to fetch game duration: %w", err)
...@@ -63,7 +63,7 @@ func (f *DisputeGameContract) GetGameDuration(ctx context.Context) (uint64, erro ...@@ -63,7 +63,7 @@ func (f *DisputeGameContract) GetGameDuration(ctx context.Context) (uint64, erro
return result.GetUint64(0), nil return result.GetUint64(0), nil
} }
func (f *DisputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, error) { func (f *disputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodMaxGameDepth)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodMaxGameDepth))
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to fetch max game depth: %w", err) return 0, fmt.Errorf("failed to fetch max game depth: %w", err)
...@@ -71,7 +71,7 @@ func (f *DisputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, erro ...@@ -71,7 +71,7 @@ func (f *DisputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, erro
return result.GetBigInt(0).Uint64(), nil return result.GetBigInt(0).Uint64(), nil
} }
func (f *DisputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (common.Hash, error) { func (f *disputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (common.Hash, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodAbsolutePrestate)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodAbsolutePrestate))
if err != nil { if err != nil {
return common.Hash{}, fmt.Errorf("failed to fetch absolute prestate hash: %w", err) return common.Hash{}, fmt.Errorf("failed to fetch absolute prestate hash: %w", err)
...@@ -79,7 +79,7 @@ func (f *DisputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (comm ...@@ -79,7 +79,7 @@ func (f *DisputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (comm
return result.GetHash(0), nil return result.GetHash(0), nil
} }
func (f *DisputeGameContract) GetL1Head(ctx context.Context) (common.Hash, error) { func (f *disputeGameContract) GetL1Head(ctx context.Context) (common.Hash, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodL1Head)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodL1Head))
if err != nil { if err != nil {
return common.Hash{}, fmt.Errorf("failed to fetch L1 head: %w", err) return common.Hash{}, fmt.Errorf("failed to fetch L1 head: %w", err)
...@@ -87,7 +87,7 @@ func (f *DisputeGameContract) GetL1Head(ctx context.Context) (common.Hash, error ...@@ -87,7 +87,7 @@ func (f *DisputeGameContract) GetL1Head(ctx context.Context) (common.Hash, error
return result.GetHash(0), nil return result.GetHash(0), nil
} }
func (f *DisputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStatus, error) { func (f *disputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStatus, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodStatus)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodStatus))
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to fetch status: %w", err) return 0, fmt.Errorf("failed to fetch status: %w", err)
...@@ -95,7 +95,7 @@ func (f *DisputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStat ...@@ -95,7 +95,7 @@ func (f *DisputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStat
return gameTypes.GameStatusFromUint8(result.GetUint8(0)) return gameTypes.GameStatusFromUint8(result.GetUint8(0))
} }
func (f *DisputeGameContract) GetClaimCount(ctx context.Context) (uint64, error) { func (f *disputeGameContract) GetClaimCount(ctx context.Context) (uint64, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodClaimCount)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodClaimCount))
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to fetch claim count: %w", err) return 0, fmt.Errorf("failed to fetch claim count: %w", err)
...@@ -103,7 +103,7 @@ func (f *DisputeGameContract) GetClaimCount(ctx context.Context) (uint64, error) ...@@ -103,7 +103,7 @@ func (f *DisputeGameContract) GetClaimCount(ctx context.Context) (uint64, error)
return result.GetBigInt(0).Uint64(), nil return result.GetBigInt(0).Uint64(), nil
} }
func (f *DisputeGameContract) GetClaim(ctx context.Context, idx uint64) (types.Claim, error) { func (f *disputeGameContract) GetClaim(ctx context.Context, idx uint64) (types.Claim, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodClaim, new(big.Int).SetUint64(idx))) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodClaim, new(big.Int).SetUint64(idx)))
if err != nil { if err != nil {
return types.Claim{}, fmt.Errorf("failed to fetch claim %v: %w", idx, err) return types.Claim{}, fmt.Errorf("failed to fetch claim %v: %w", idx, err)
...@@ -111,7 +111,7 @@ func (f *DisputeGameContract) GetClaim(ctx context.Context, idx uint64) (types.C ...@@ -111,7 +111,7 @@ func (f *DisputeGameContract) GetClaim(ctx context.Context, idx uint64) (types.C
return f.decodeClaim(result, int(idx)), nil return f.decodeClaim(result, int(idx)), nil
} }
func (f *DisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim, error) { func (f *disputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim, error) {
count, err := f.GetClaimCount(ctx) count, err := f.GetClaimCount(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load claim count: %w", err) return nil, fmt.Errorf("failed to load claim count: %w", err)
...@@ -134,7 +134,7 @@ func (f *DisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim, ...@@ -134,7 +134,7 @@ func (f *DisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim,
return claims, nil return claims, nil
} }
func (f *DisputeGameContract) vm(ctx context.Context) (*VMContract, error) { func (f *disputeGameContract) vm(ctx context.Context) (*VMContract, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodVM)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodVM))
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to fetch VM addr: %w", err) return nil, fmt.Errorf("failed to fetch VM addr: %w", err)
...@@ -143,22 +143,22 @@ func (f *DisputeGameContract) vm(ctx context.Context) (*VMContract, error) { ...@@ -143,22 +143,22 @@ func (f *DisputeGameContract) vm(ctx context.Context) (*VMContract, error) {
return NewVMContract(vmAddr, f.multiCaller) return NewVMContract(vmAddr, f.multiCaller)
} }
func (f *DisputeGameContract) AttackTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) { func (f *disputeGameContract) AttackTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) {
call := f.contract.Call(methodAttack, new(big.Int).SetUint64(parentContractIndex), pivot) call := f.contract.Call(methodAttack, new(big.Int).SetUint64(parentContractIndex), pivot)
return call.ToTxCandidate() return call.ToTxCandidate()
} }
func (f *DisputeGameContract) DefendTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) { func (f *disputeGameContract) DefendTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) {
call := f.contract.Call(methodDefend, new(big.Int).SetUint64(parentContractIndex), pivot) call := f.contract.Call(methodDefend, new(big.Int).SetUint64(parentContractIndex), pivot)
return call.ToTxCandidate() return call.ToTxCandidate()
} }
func (f *DisputeGameContract) StepTx(claimIdx uint64, isAttack bool, stateData []byte, proof []byte) (txmgr.TxCandidate, error) { func (f *disputeGameContract) StepTx(claimIdx uint64, isAttack bool, stateData []byte, proof []byte) (txmgr.TxCandidate, error) {
call := f.contract.Call(methodStep, new(big.Int).SetUint64(claimIdx), isAttack, stateData, proof) call := f.contract.Call(methodStep, new(big.Int).SetUint64(claimIdx), isAttack, stateData, proof)
return call.ToTxCandidate() return call.ToTxCandidate()
} }
func (f *DisputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uint64) error { func (f *disputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uint64) error {
call := f.resolveClaimCall(claimIdx) call := f.resolveClaimCall(claimIdx)
_, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call) _, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call)
if err != nil { if err != nil {
...@@ -167,16 +167,16 @@ func (f *DisputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uin ...@@ -167,16 +167,16 @@ func (f *DisputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uin
return nil return nil
} }
func (f *DisputeGameContract) ResolveClaimTx(claimIdx uint64) (txmgr.TxCandidate, error) { func (f *disputeGameContract) ResolveClaimTx(claimIdx uint64) (txmgr.TxCandidate, error) {
call := f.resolveClaimCall(claimIdx) call := f.resolveClaimCall(claimIdx)
return call.ToTxCandidate() return call.ToTxCandidate()
} }
func (f *DisputeGameContract) resolveClaimCall(claimIdx uint64) *batching.ContractCall { func (f *disputeGameContract) resolveClaimCall(claimIdx uint64) *batching.ContractCall {
return f.contract.Call(methodResolveClaim, new(big.Int).SetUint64(claimIdx)) return f.contract.Call(methodResolveClaim, new(big.Int).SetUint64(claimIdx))
} }
func (f *DisputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameStatus, error) { func (f *disputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameStatus, error) {
call := f.resolveCall() call := f.resolveCall()
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call)
if err != nil { if err != nil {
...@@ -185,16 +185,16 @@ func (f *DisputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameSt ...@@ -185,16 +185,16 @@ func (f *DisputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameSt
return gameTypes.GameStatusFromUint8(result.GetUint8(0)) return gameTypes.GameStatusFromUint8(result.GetUint8(0))
} }
func (f *DisputeGameContract) ResolveTx() (txmgr.TxCandidate, error) { func (f *disputeGameContract) ResolveTx() (txmgr.TxCandidate, error) {
call := f.resolveCall() call := f.resolveCall()
return call.ToTxCandidate() return call.ToTxCandidate()
} }
func (f *DisputeGameContract) resolveCall() *batching.ContractCall { func (f *disputeGameContract) resolveCall() *batching.ContractCall {
return f.contract.Call(methodResolve) return f.contract.Call(methodResolve)
} }
func (f *DisputeGameContract) decodeClaim(result *batching.CallResult, contractIndex int) types.Claim { func (f *disputeGameContract) decodeClaim(result *batching.CallResult, contractIndex int) types.Claim {
parentIndex := result.GetUint32(0) parentIndex := result.GetUint32(0)
countered := result.GetBool(1) countered := result.GetBool(1)
claim := result.GetHash(2) claim := result.GetHash(2)
......
...@@ -20,7 +20,7 @@ var ( ...@@ -20,7 +20,7 @@ var (
oracleAddr = common.HexToAddress("0x44442842371dFC380576ebb09Ae16Cb6B6ca4444") oracleAddr = common.HexToAddress("0x44442842371dFC380576ebb09Ae16Cb6B6ca4444")
) )
type disputeGameSetupFunc func(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameContract) type disputeGameSetupFunc func(t *testing.T) (*batchingTest.AbiBasedRpc, *disputeGameContract)
func runCommonDisputeGameTests(t *testing.T, setup disputeGameSetupFunc) { func runCommonDisputeGameTests(t *testing.T, setup disputeGameSetupFunc) {
tests := []struct { tests := []struct {
...@@ -52,19 +52,19 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) { ...@@ -52,19 +52,19 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) {
args []interface{} args []interface{}
result interface{} result interface{}
expected interface{} // Defaults to expecting the same as result expected interface{} // Defaults to expecting the same as result
call func(game *DisputeGameContract) (any, error) call func(game *disputeGameContract) (any, error)
}{ }{
{ {
method: methodStatus, method: methodStatus,
result: types.GameStatusChallengerWon, result: types.GameStatusChallengerWon,
call: func(game *DisputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetStatus(context.Background()) return game.GetStatus(context.Background())
}, },
}, },
{ {
method: methodGameDuration, method: methodGameDuration,
result: uint64(5566), result: uint64(5566),
call: func(game *DisputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetGameDuration(context.Background()) return game.GetGameDuration(context.Background())
}, },
}, },
...@@ -72,14 +72,14 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) { ...@@ -72,14 +72,14 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) {
method: methodMaxGameDepth, method: methodMaxGameDepth,
result: big.NewInt(128), result: big.NewInt(128),
expected: uint64(128), expected: uint64(128),
call: func(game *DisputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetMaxGameDepth(context.Background()) return game.GetMaxGameDepth(context.Background())
}, },
}, },
{ {
method: methodAbsolutePrestate, method: methodAbsolutePrestate,
result: common.Hash{0xab}, result: common.Hash{0xab},
call: func(game *DisputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetAbsolutePrestateHash(context.Background()) return game.GetAbsolutePrestateHash(context.Background())
}, },
}, },
...@@ -87,21 +87,21 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) { ...@@ -87,21 +87,21 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) {
method: methodClaimCount, method: methodClaimCount,
result: big.NewInt(9876), result: big.NewInt(9876),
expected: uint64(9876), expected: uint64(9876),
call: func(game *DisputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetClaimCount(context.Background()) return game.GetClaimCount(context.Background())
}, },
}, },
{ {
method: methodL1Head, method: methodL1Head,
result: common.Hash{0xdd, 0xbb}, result: common.Hash{0xdd, 0xbb},
call: func(game *DisputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetL1Head(context.Background()) return game.GetL1Head(context.Background())
}, },
}, },
{ {
method: methodResolve, method: methodResolve,
result: types.GameStatusInProgress, result: types.GameStatusInProgress,
call: func(game *DisputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.CallResolve(context.Background()) return game.CallResolve(context.Background())
}, },
}, },
......
...@@ -17,7 +17,7 @@ const ( ...@@ -17,7 +17,7 @@ const (
) )
type FaultDisputeGameContract struct { type FaultDisputeGameContract struct {
DisputeGameContract disputeGameContract
} }
func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCaller) (*FaultDisputeGameContract, error) { func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCaller) (*FaultDisputeGameContract, error) {
...@@ -27,7 +27,7 @@ func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCall ...@@ -27,7 +27,7 @@ func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCall
} }
return &FaultDisputeGameContract{ return &FaultDisputeGameContract{
DisputeGameContract: DisputeGameContract{ disputeGameContract: disputeGameContract{
multiCaller: caller, multiCaller: caller,
contract: batching.NewBoundContract(fdgAbi, addr), contract: batching.NewBoundContract(fdgAbi, addr),
}, },
......
...@@ -14,9 +14,9 @@ import ( ...@@ -14,9 +14,9 @@ import (
) )
func TestFaultDisputeGameContract_CommonTests(t *testing.T) { func TestFaultDisputeGameContract_CommonTests(t *testing.T) {
runCommonDisputeGameTests(t, func(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameContract) { runCommonDisputeGameTests(t, func(t *testing.T) (*batchingTest.AbiBasedRpc, *disputeGameContract) {
stubRpc, contract := setupFaultDisputeGameTest(t) stubRpc, contract := setupFaultDisputeGameTest(t)
return stubRpc, &contract.DisputeGameContract return stubRpc, &contract.disputeGameContract
}) })
} }
......
...@@ -19,7 +19,7 @@ var ( ...@@ -19,7 +19,7 @@ var (
) )
type OutputBisectionGameContract struct { type OutputBisectionGameContract struct {
DisputeGameContract disputeGameContract
} }
func NewOutputBisectionGameContract(addr common.Address, caller *batching.MultiCaller) (*OutputBisectionGameContract, error) { func NewOutputBisectionGameContract(addr common.Address, caller *batching.MultiCaller) (*OutputBisectionGameContract, error) {
...@@ -29,7 +29,7 @@ func NewOutputBisectionGameContract(addr common.Address, caller *batching.MultiC ...@@ -29,7 +29,7 @@ func NewOutputBisectionGameContract(addr common.Address, caller *batching.MultiC
} }
return &OutputBisectionGameContract{ return &OutputBisectionGameContract{
DisputeGameContract: DisputeGameContract{ disputeGameContract: disputeGameContract{
multiCaller: caller, multiCaller: caller,
contract: batching.NewBoundContract(contractAbi, addr), contract: batching.NewBoundContract(contractAbi, addr),
}, },
...@@ -78,7 +78,7 @@ func (f *OutputBisectionGameContract) addLocalDataTx(claimIdx uint64, data *type ...@@ -78,7 +78,7 @@ func (f *OutputBisectionGameContract) addLocalDataTx(claimIdx uint64, data *type
return call.ToTxCandidate() return call.ToTxCandidate()
} }
func (f *DisputeGameContract) addGlobalDataTx(ctx context.Context, data *types.PreimageOracleData) (txmgr.TxCandidate, error) { func (f *disputeGameContract) addGlobalDataTx(ctx context.Context, data *types.PreimageOracleData) (txmgr.TxCandidate, error) {
vm, err := f.vm(ctx) vm, err := f.vm(ctx)
if err != nil { if err != nil {
return txmgr.TxCandidate{}, err return txmgr.TxCandidate{}, err
......
...@@ -14,9 +14,9 @@ import ( ...@@ -14,9 +14,9 @@ import (
) )
func TestOutputBisectionGameContract_CommonTests(t *testing.T) { func TestOutputBisectionGameContract_CommonTests(t *testing.T) {
runCommonDisputeGameTests(t, func(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameContract) { runCommonDisputeGameTests(t, func(t *testing.T) (*batchingTest.AbiBasedRpc, *disputeGameContract) {
stubRpc, contract := setupOutputBisectionGameTest(t) stubRpc, contract := setupOutputBisectionGameTest(t)
return stubRpc, &contract.DisputeGameContract return stubRpc, &contract.disputeGameContract
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment