Skip to content

Commit

Permalink
Update ActionBenchmark to use single ExpectedOutput (#1608)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbuchwald authored Sep 30, 2024
1 parent e78841e commit 3e358c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
6 changes: 3 additions & 3 deletions chain/chaintest/action_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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()
Expand Down
19 changes: 7 additions & 12 deletions examples/morpheusvm/actions/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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)
Expand Down

0 comments on commit 3e358c1

Please sign in to comment.