From 618a87e56e067044452b7053a3c1244b3415ac02 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Mon, 30 Sep 2024 10:28:43 -0400 Subject: [PATCH] Update ActionBenchmark to use single ExpectedOutput --- chain/chaintest/action_test_helpers.go | 6 +++--- examples/morpheusvm/actions/transfer_test.go | 19 +++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/chain/chaintest/action_test_helpers.go b/chain/chaintest/action_test_helpers.go index c730f24467..be469cb0a6 100644 --- a/chain/chaintest/action_test_helpers.go +++ b/chain/chaintest/action_test_helpers.go @@ -95,8 +95,8 @@ type ActionBenchmark struct { Actor codec.Address ActionID ids.ID - ExpectedOutputs []codec.Typed - ExpectedErr error + ExpectedOutput codec.Typed + ExpectedErr error Assertion func(context.Context, *testing.B, state.Mutable) } @@ -115,7 +115,7 @@ func (test *ActionBenchmark) Run(ctx context.Context, b *testing.B) { for i := 0; i < b.N; i++ { output, err := test.Action.Execute(ctx, test.Rules, states[i], test.Timestamp, test.Actor, test.ActionID) require.NoError(err) - require.Equal(test.ExpectedOutputs[i], output) + require.Equal(test.ExpectedOutput, output) } b.StopTimer() diff --git a/examples/morpheusvm/actions/transfer_test.go b/examples/morpheusvm/actions/transfer_test.go index fd55ff2f23..e232797587 100644 --- a/examples/morpheusvm/actions/transfer_test.go +++ b/examples/morpheusvm/actions/transfer_test.go @@ -131,7 +131,7 @@ func TestTransferAction(t *testing.T) { } func BenchmarkSimpleTransfer(b *testing.B) { - require := require.New(b) + setupRequire := require.New(b) to := codec.CreateAddress(0, ids.GenerateTestID()) from := codec.CreateAddress(0, ids.GenerateTestID()) @@ -142,23 +142,18 @@ func BenchmarkSimpleTransfer(b *testing.B) { To: to, Value: 1, }, - ExpectedOutputs: func() []codec.Typed { - outputs := make([]codec.Typed, 0) - for i := 0; i < b.N; i++ { - outputs = append(outputs, &TransferResult{ - SenderBalance: 0, - ReceiverBalance: 1, - }) - } - return outputs - }(), + ExpectedOutput: &TransferResult{ + SenderBalance: 0, + ReceiverBalance: 1, + }, CreateState: func() state.Mutable { store := chaintest.NewInMemoryStore() err := storage.SetBalance(context.Background(), store, from, 1) - require.NoError(err) + setupRequire.NoError(err) return store }, Assertion: func(ctx context.Context, b *testing.B, store state.Mutable) { + require := require.New(b) toBalance, err := storage.GetBalance(ctx, store, to) require.NoError(err) require.Equal(uint64(1), toBalance)