Commit cbf3628a authored by Adrian Sutton's avatar Adrian Sutton

op-challenger: Simplify exposed API for dispute game proposals.

parent b01ff541
......@@ -36,12 +36,27 @@ type FaultDisputeGameContract struct {
contract *batching.BoundContract
}
type Proposal struct {
// contractProposal matches the structure for output root proposals used by the contracts.
// It must exactly match the contract structure. The exposed API uses Proposal to decouple the contract
// and challenger representations of the proposal data.
type contractProposal struct {
Index *big.Int
L2BlockNumber *big.Int
OutputRoot common.Hash
}
type Proposal struct {
L2BlockNumber *big.Int
OutputRoot common.Hash
}
func asProposal(p contractProposal) Proposal {
return Proposal{
L2BlockNumber: p.L2BlockNumber,
OutputRoot: p.OutputRoot,
}
}
func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCaller) (*FaultDisputeGameContract, error) {
fdgAbi, err := bindings.FaultDisputeGameMetaData.GetAbi()
if err != nil {
......@@ -93,10 +108,10 @@ func (f *FaultDisputeGameContract) GetProposals(ctx context.Context) (Proposal,
return Proposal{}, Proposal{}, fmt.Errorf("failed to fetch proposals: %w", err)
}
var agreed, disputed Proposal
var agreed, disputed contractProposal
result.GetStruct(0, &agreed)
result.GetStruct(1, &disputed)
return agreed, disputed, nil
return asProposal(agreed), asProposal(disputed), nil
}
func (f *FaultDisputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStatus, error) {
......
......@@ -105,23 +105,31 @@ func TestGetProposals(t *testing.T) {
disputedIndex := big.NewInt(7)
disputedBlockNum := big.NewInt(8)
disputedRoot := common.Hash{0xdd}
agreed := Proposal{
agreed := contractProposal{
Index: agreedIndex,
L2BlockNumber: agreedBlockNum,
OutputRoot: agreedRoot,
}
disputed := Proposal{
disputed := contractProposal{
Index: disputedIndex,
L2BlockNumber: disputedBlockNum,
OutputRoot: disputedRoot,
}
expectedAgreed := Proposal{
L2BlockNumber: agreed.L2BlockNumber,
OutputRoot: agreed.OutputRoot,
}
expectedDisputed := Proposal{
L2BlockNumber: disputed.L2BlockNumber,
OutputRoot: disputed.OutputRoot,
}
stubRpc.SetResponse(fdgAddr, methodProposals, batching.BlockLatest, []interface{}{}, []interface{}{
agreed, disputed,
})
actualAgreed, actualDisputed, err := game.GetProposals(context.Background())
require.NoError(t, err)
require.Equal(t, agreed, actualAgreed)
require.Equal(t, disputed, actualDisputed)
require.Equal(t, expectedAgreed, actualAgreed)
require.Equal(t, expectedDisputed, actualDisputed)
}
func TestGetClaim(t *testing.T) {
......
......@@ -17,12 +17,10 @@ func TestFetchLocalInputs(t *testing.T) {
contract := &mockGameInputsSource{
l1Head: common.Hash{0xcc},
starting: contracts.Proposal{
Index: big.NewInt(6),
L2BlockNumber: big.NewInt(2222),
OutputRoot: common.Hash{0xdd},
},
disputed: contracts.Proposal{
Index: big.NewInt(7),
L2BlockNumber: big.NewInt(3333),
OutputRoot: common.Hash{0xee},
},
......
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