Skip to content

Commit

Permalink
fix: we had an issue in the test when running in parallel
Browse files Browse the repository at this point in the history
it could either remove or add the policy at the same time someone else was checking for another scenario

to fix I added the adding flow, to updating/changing tx before making the update with the same asserting checks for correct adding.
  • Loading branch information
afa7789 committed Oct 18, 2024
1 parent 5c7b977 commit c1506b6
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions zk/txpool/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,39 @@ func TestUpdatePolicies(t *testing.T) {
t.Parallel()

// Create test addresses and policies
addr1 := common.HexToAddress("0x1234567890abcdef")
addr2 := common.HexToAddress("0xabcdef1234567890")
addr1 := common.HexToAddress("0x1234567890abcdea")
addr2 := common.HexToAddress("0xabcdef1234567891")
policiesOld := [][]Policy{
{SendTx, Deploy},
{SendTx},
}

err := UpdatePolicies(ctx, db, "blocklist", []common.Address{addr1, addr2}, policiesOld)
require.NoError(t, err)

// Check if the policies are added correctly
hasPolicy, err := DoesAccountHavePolicy(ctx, db, addr1, SendTx)
require.NoError(t, err)
require.True(t, hasPolicy)

hasPolicy, err = DoesAccountHavePolicy(ctx, db, addr1, Deploy)
require.NoError(t, err)
require.True(t, hasPolicy)

hasPolicy, err = DoesAccountHavePolicy(ctx, db, addr2, SendTx)
require.NoError(t, err)
require.True(t, hasPolicy)

policies := [][]Policy{
{},
{SendTx},
}

err := UpdatePolicies(ctx, db, "blocklist", []common.Address{addr1, addr2}, policies)
err = UpdatePolicies(ctx, db, "blocklist", []common.Address{addr1, addr2}, policies)
require.NoError(t, err)

// Check if the policies are removed correctly
hasPolicy, err := DoesAccountHavePolicy(ctx, db, addr1, SendTx)
hasPolicy, err = DoesAccountHavePolicy(ctx, db, addr1, SendTx)
require.NoError(t, err)
require.False(t, hasPolicy)

Expand All @@ -324,18 +345,42 @@ func TestUpdatePolicies(t *testing.T) {
t.Parallel()

// Create test addresses and policies
addr1 := common.HexToAddress("0x1234567890abcdef")
addr2 := common.HexToAddress("0xabcdef1234567890")
addr1 := common.HexToAddress("0x1234567890abcded")
addr2 := common.HexToAddress("0xabcdef1234567893")

// first add these policies
policiesOld := [][]Policy{
{SendTx, Deploy},
{SendTx},
}

err := UpdatePolicies(ctx, db, "blocklist", []common.Address{addr1, addr2}, policiesOld)
require.NoError(t, err)

// Check if the policies are added correctly
hasPolicy, err := DoesAccountHavePolicy(ctx, db, addr1, SendTx)
require.NoError(t, err)
require.True(t, hasPolicy)

hasPolicy, err = DoesAccountHavePolicy(ctx, db, addr1, Deploy)
require.NoError(t, err)
require.True(t, hasPolicy)

hasPolicy, err = DoesAccountHavePolicy(ctx, db, addr2, SendTx)
require.NoError(t, err)
require.True(t, hasPolicy)

// then remove policies
policies := [][]Policy{
{},
{},
}

err := UpdatePolicies(ctx, db, "blocklist", []common.Address{addr1, addr2}, policies)
err = UpdatePolicies(ctx, db, "blocklist", []common.Address{addr1, addr2}, policies)
require.NoError(t, err)

// Check if the policies are removed correctly
hasPolicy, err := DoesAccountHavePolicy(ctx, db, addr1, SendTx)
hasPolicy, err = DoesAccountHavePolicy(ctx, db, addr1, SendTx)
require.NoError(t, err)
require.False(t, hasPolicy)

Expand Down

0 comments on commit c1506b6

Please sign in to comment.