Skip to content

Commit

Permalink
Replace util function with existing TestClient one
Browse files Browse the repository at this point in the history
  • Loading branch information
gligneul committed Oct 3, 2024
1 parent 7b0fe6d commit 103ad5b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
13 changes: 8 additions & 5 deletions system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func (tc *TestClient) GetBaseFeeAt(t *testing.T, blockNum *big.Int) *big.Int {
return GetBaseFeeAt(t, tc.Client, tc.ctx, blockNum)
}

func (tc *TestClient) SendWaitTestTransactions(t *testing.T, txs []*types.Transaction) {
SendWaitTestTransactions(t, tc.ctx, tc.Client, txs)
func (tc *TestClient) SendWaitTestTransactions(t *testing.T, txs []*types.Transaction) []*types.Receipt {
return SendWaitTestTransactions(t, tc.ctx, tc.Client, txs)
}

func (tc *TestClient) DeploySimple(t *testing.T, auth bind.TransactOpts) (common.Address, *mocksgen.Simple) {
Expand Down Expand Up @@ -763,15 +763,18 @@ func (b *NodeBuilder) BridgeBalance(t *testing.T, account string, amount *big.In
return BridgeBalance(t, account, amount, b.L1Info, b.L2Info, b.L1.Client, b.L2.Client, b.ctx)
}

func SendWaitTestTransactions(t *testing.T, ctx context.Context, client *ethclient.Client, txs []*types.Transaction) {
func SendWaitTestTransactions(t *testing.T, ctx context.Context, client *ethclient.Client, txs []*types.Transaction) []*types.Receipt {
t.Helper()
receipts := make([]*types.Receipt, len(txs))
for _, tx := range txs {
Require(t, client.SendTransaction(ctx, tx))
}
for _, tx := range txs {
_, err := EnsureTxSucceeded(ctx, client, tx)
for i, tx := range txs {
var err error
receipts[i], err = EnsureTxSucceeded(ctx, client, tx)
Require(t, err)
}
return receipts
}

func TransferBalance(
Expand Down
26 changes: 10 additions & 16 deletions system_tests/program_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,18 @@ func compareGasUsage(
}

const txGas uint64 = 32_000_000
tx := builder.L2Info.PrepareTxTo("Owner", &evmContract, txGas, txValue, txData)
evmGas := sendAndEnsureTransaction(t, builder.ctx, builder.L2.Client, tx)
evmGasUsage, err := evmOpcodesGasUsage(builder.ctx, builder.L2.Client.Client(), tx)
txs := []*types.Transaction{
builder.L2Info.PrepareTxTo("Owner", &evmContract, txGas, txValue, txData),
builder.L2Info.PrepareTxTo("Owner", &stylusContract, txGas, txValue, txData),
}
receipts := builder.L2.SendWaitTestTransactions(t, txs)

evmGas := receipts[0].GasUsedForL2()
evmGasUsage, err := evmOpcodesGasUsage(builder.ctx, builder.L2.Client.Client(), txs[0])
Require(t, err)

tx = builder.L2Info.PrepareTxTo("Owner", &stylusContract, txGas, txValue, txData)
stylusGas := sendAndEnsureTransaction(t, builder.ctx, builder.L2.Client, tx)
stylusGasUsage, err := stylusHostiosGasUsage(builder.ctx, builder.L2.Client.Client(), tx)
stylusGas := receipts[1].GasUsedForL2()
stylusGasUsage, err := stylusHostiosGasUsage(builder.ctx, builder.L2.Client.Client(), txs[1])
Require(t, err)

t.Logf("evm total usage: %v - stylus total usage: %v", evmGas, stylusGas)
Expand Down Expand Up @@ -415,13 +419,3 @@ func checkPercentDiff(t *testing.T, a, b float64, maxAllowedDifference float64)
Fatal(t, fmt.Sprintf("gas usages are too different; got %v, max allowed is %v", percentageDifference, maxAllowedDifference))
}
}

// sendAndEnsureTransaction sends a transaction, ensures it succeed, and returns the total gas cost.
func sendAndEnsureTransaction(t *testing.T, ctx context.Context, client *ethclient.Client, tx *types.Transaction) uint64 {
t.Helper()
err := client.SendTransaction(ctx, tx)
Require(t, err)
receipt, err := EnsureTxSucceeded(ctx, client, tx)
Require(t, err)
return receipt.GasUsedForL2()
}

0 comments on commit 103ad5b

Please sign in to comment.