Skip to content

Commit

Permalink
test/integ: deal with lack of refund with delay
Browse files Browse the repository at this point in the history
The slowest <1/3 of validators will routinely miss having their approval
votes included in a block that contains the resolution. As a result, they
will not get the refund expected when placing a valid vote. To deal with
this possibility in the tests where we check expected balance changes,
sleep a little after deposit transactions are resolved so that the late
approval can be mined in the subsequent block.  Without the delay, the
balance will be less the gas consumed by the approve txn.
  • Loading branch information
jchappelow committed Mar 28, 2024
1 parent f738faa commit a9930db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/integration/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ func (r *IntHelper) RunDockerComposeWithServices(ctx context.Context, services [
err = stack.Up(ctx, compose.Wait(true), compose.RunServices(services...))
r.t.Log("docker compose up")

time.Sleep(3 * time.Second) // RPC errors with chain_info and other stuff... trying anything now

require.NoError(r.t, err, "failed to start kwild cluster services %v", services)

for _, name := range services {
Expand Down
12 changes: 11 additions & 1 deletion test/specifications/eth_deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func DepositSuccessSpecification(ctx context.Context, t *testing.T, deployer Dep
require.NoError(t, err)
return postUserBalance.Cmp(big.NewInt(0).Add(preUserBalance, amount)) == 0
}, 1*time.Minute, 5*time.Second)

time.Sleep(2 * time.Second)
}

func DepositFailSpecification(ctx context.Context, t *testing.T, deployer DeployerDsl) {
Expand Down Expand Up @@ -150,6 +152,8 @@ func DeployDbInsufficientFundsSpecification(ctx context.Context, t *testing.T, d
return postUserBalance.Cmp(big.NewInt(0).Add(preUserBalance, amount)) == 0
}, 5*time.Minute, 5*time.Second)

time.Sleep(2 * time.Second)

// Should be able to deploy database
db := SchemaLoader.Load(t, SchemaTestDB)

Expand Down Expand Up @@ -202,7 +206,9 @@ func FundValidatorSpecification(ctx context.Context, t *testing.T, sender Deploy
bal2, err = sender.AccountBalance(ctx, senderAddr)
require.NoError(t, err)
return bal2.Cmp(big.NewInt(0).Add(bal1, amt)) == 0
}, 5*time.Minute, 5*time.Second)
}, 5*time.Minute, 5*time.Second) // if receiver voted, they'd get the refund here, at same time as dep

time.Sleep(2 * time.Second) // wait for receiver to vote if they were too late for resoln

preValBal, err := sender.AccountBalance(ctx, receiverId)
require.NoError(t, err)
Expand All @@ -214,6 +220,8 @@ func FundValidatorSpecification(ctx context.Context, t *testing.T, sender Deploy
// I expect success
expectTxSuccess(t, sender, ctx, txHash, defaultTxQueryTimeout)()

time.Sleep(2 * time.Second) // it reports the old state very briefly, wait a sec

// Check the validator account balance
postBal, err := sender.AccountBalance(ctx, receiverId)
require.NoError(t, err)
Expand Down Expand Up @@ -262,6 +270,8 @@ func DeployDbSuccessSpecification(ctx context.Context, t *testing.T, deployer De
// Then i expect success
expectTxSuccess(t, deployer, ctx, txHash, defaultTxQueryTimeout)()

time.Sleep(2 * time.Second)

// And i expect database should exist
err = deployer.DatabaseExists(ctx, deployer.DBID(db.Name))
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion test/specifications/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ func expectTxFail(t *testing.T, spec TxQueryDsl, ctx context.Context, txHash []b
// prevent appending to the prior invocation(s)
status.Reset()
if err := spec.TxSuccess(ctx, txHash); err == nil {
status.WriteString("success")
return false
} else {
status.WriteString(err.Error())
// NOTE: ErrTxNotConfirmed is not considered a failure, should retry
return !errors.Is(err, driver.ErrTxNotConfirmed)
}
}, waitFor, time.Second*1, "tx should fail - status: %v", status.String())
}, waitFor, time.Second*1, "tx should fail - status: %v, hash %x", status.String(), txHash)
}
}

0 comments on commit a9930db

Please sign in to comment.