Skip to content

Commit

Permalink
Optimize the variable definitions in the unit test cases to enhance r…
Browse files Browse the repository at this point in the history
…eadability and maintainability
  • Loading branch information
JustXxx committed Oct 31, 2024
1 parent 3ea18b5 commit bdb79dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
9 changes: 4 additions & 5 deletions op-challenger2/game/fault/contracts/faultdisputegame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,12 +803,11 @@ func TestAttackV2Tx(t *testing.T) {
t.Run(version.version, func(t *testing.T) {
stubRpc, game := setupFaultDisputeGameTest(t, version)
bond := big.NewInt(1044)
value := common.Hash{0xaa}
var claims [96]byte
copy(claims[0:32], value[:])
copy(claims[32:64], value[:])
copy(claims[64:96], value[:])
nBits := uint64(2)
claims := make([]byte, ((1<<nBits)-1)*32)
for i := range claims {
claims[i] = common.Hash{0xaa}[i%32]
}
attackBranch := big.NewInt(0)
daType := big.NewInt(1)
parent := faultTypes.Claim{ClaimData: faultTypes.ClaimData{Value: common.Hash{0xbb}}, ContractIndex: 111}
Expand Down
14 changes: 7 additions & 7 deletions op-challenger2/game/fault/types/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ func TestMoveN(t *testing.T) {
}

tests3 := []struct {
startGIndex *big.Int
defendGIndex *big.Int
startGIndex *big.Int
postGIndex *big.Int
}{
{bi(4), bi(28)},
{bi(8), bi(44)},
Expand All @@ -360,15 +360,15 @@ func TestMoveN(t *testing.T) {
for _, test := range tests3 {
pos := NewPositionFromGIndex(test.startGIndex)
result := pos.MoveN(depth, branch)
require.Equalf(t, test.defendGIndex, result.ToGIndex(), "move GIndex %s, expected=%s, got=%s", test.startGIndex, test.defendGIndex, result.ToGIndex())
require.Equalf(t, test.postGIndex, result.ToGIndex(), "move GIndex %s, expected=%s, got=%s", test.startGIndex, test.postGIndex, result.ToGIndex())
}
}

func TestMoveRightN(t *testing.T) {
tests := []struct {
startGIndex *big.Int
moveN uint64
defendGIndex *big.Int
startGIndex *big.Int
moveN uint64
postGIndex *big.Int
}{
{bi(2), 1, bi(3)},
{bi(4), 2, bi(6)},
Expand All @@ -378,6 +378,6 @@ func TestMoveRightN(t *testing.T) {
for _, test := range tests {
pos := NewPositionFromGIndex(test.startGIndex)
result := pos.MoveRightN(test.moveN)
require.Equalf(t, test.defendGIndex, result.ToGIndex(), "move GIndex %s, MoveN %s, expected=%s, got=%s", test.startGIndex, test.moveN, test.defendGIndex, result.ToGIndex())
require.Equalf(t, test.postGIndex, result.ToGIndex(), "move GIndex %s, MoveN %s, expected=%s, got=%s", test.startGIndex, test.moveN, test.postGIndex, result.ToGIndex())
}
}

0 comments on commit bdb79dd

Please sign in to comment.