Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ActionBenchmark to use single ExpectedOutput #1608

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading