Commit 786cca3d authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-challenger: Include bond with create game transactions (#9922)

parent 6483bb21
...@@ -43,7 +43,7 @@ func CreateGame(ctx *cli.Context) error { ...@@ -43,7 +43,7 @@ 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(uint32(traceType), outputRoot, l2BlockNum) txCandidate, err := contract.CreateTx(ctx.Context, uint32(traceType), outputRoot, l2BlockNum)
if err != nil { if err != nil {
return fmt.Errorf("failed to create tx: %w", err) return fmt.Errorf("failed to create tx: %w", err)
} }
......
...@@ -17,6 +17,7 @@ const ( ...@@ -17,6 +17,7 @@ const (
methodGameCount = "gameCount" methodGameCount = "gameCount"
methodGameAtIndex = "gameAtIndex" methodGameAtIndex = "gameAtIndex"
methodGameImpls = "gameImpls" methodGameImpls = "gameImpls"
methodInitBonds = "initBonds"
methodCreateGame = "create" methodCreateGame = "create"
methodGames = "games" methodGames = "games"
) )
...@@ -135,9 +136,19 @@ func (f *DisputeGameFactoryContract) GetAllGames(ctx context.Context, blockHash ...@@ -135,9 +136,19 @@ func (f *DisputeGameFactoryContract) GetAllGames(ctx context.Context, blockHash
return games, nil return games, nil
} }
func (f *DisputeGameFactoryContract) CreateTx(traceType uint32, outputRoot common.Hash, l2BlockNum uint64) (txmgr.TxCandidate, error) { func (f *DisputeGameFactoryContract) CreateTx(ctx context.Context, traceType uint32, outputRoot common.Hash, l2BlockNum uint64) (txmgr.TxCandidate, error) {
result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodInitBonds, traceType))
if err != nil {
return txmgr.TxCandidate{}, fmt.Errorf("failed to fetch init bond: %w", err)
}
initBond := result.GetBigInt(0)
call := f.contract.Call(methodCreateGame, traceType, outputRoot, common.BigToHash(big.NewInt(int64(l2BlockNum))).Bytes()) call := f.contract.Call(methodCreateGame, traceType, outputRoot, common.BigToHash(big.NewInt(int64(l2BlockNum))).Bytes())
return call.ToTxCandidate() candidate, err := call.ToTxCandidate()
if err != nil {
return txmgr.TxCandidate{}, err
}
candidate.Value = initBond
return candidate, err
} }
func (f *DisputeGameFactoryContract) decodeGame(result *batching.CallResult) types.GameMetadata { func (f *DisputeGameFactoryContract) decodeGame(result *batching.CallResult) types.GameMetadata {
......
...@@ -212,10 +212,14 @@ func TestCreateTx(t *testing.T) { ...@@ -212,10 +212,14 @@ func TestCreateTx(t *testing.T) {
traceType := uint32(123) traceType := uint32(123)
outputRoot := common.Hash{0x01} outputRoot := common.Hash{0x01}
l2BlockNum := common.BigToHash(big.NewInt(456)).Bytes() l2BlockNum := common.BigToHash(big.NewInt(456)).Bytes()
bond := big.NewInt(49284294829)
stubRpc.SetResponse(factoryAddr, methodInitBonds, rpcblock.Latest, []interface{}{traceType}, []interface{}{bond})
stubRpc.SetResponse(factoryAddr, methodCreateGame, rpcblock.Latest, []interface{}{traceType, outputRoot, l2BlockNum}, nil) stubRpc.SetResponse(factoryAddr, methodCreateGame, rpcblock.Latest, []interface{}{traceType, outputRoot, l2BlockNum}, nil)
tx, err := factory.CreateTx(traceType, outputRoot, uint64(456)) tx, err := factory.CreateTx(context.Background(), traceType, outputRoot, uint64(456))
require.NoError(t, err) require.NoError(t, err)
stubRpc.VerifyTxCandidate(tx) stubRpc.VerifyTxCandidate(tx)
require.NotNil(t, tx.Value)
require.Truef(t, bond.Cmp(tx.Value) == 0, "Expected bond %v but was %v", bond, tx.Value)
} }
func setupDisputeGameFactoryTest(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameFactoryContract) { func setupDisputeGameFactoryTest(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameFactoryContract) {
......
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