Skip to content

Commit

Permalink
add refund integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoVillar committed Dec 16, 2024
1 parent eaf710d commit 5e619c4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions examples/morpheusvm/tests/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/ava-labs/hypersdk/api/indexer"
"github.com/ava-labs/hypersdk/auth"
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/crypto/ed25519"
Expand Down Expand Up @@ -44,3 +45,56 @@ var _ = registry.Register(TestsRegistry, "Transfer Transaction", func(t ginkgo.F

require.NoError(tn.ConfirmTxs(timeoutCtx, []*chain.Transaction{tx}))
})

var _ = registry.Register(TestsRegistry, "Read From Memory Refund", func(t ginkgo.FullGinkgoTInterface, tn tworkload.TestNetwork) {
require := require.New(t)
other, err := ed25519.GeneratePrivateKey()
require.NoError(err)
toAddress := auth.NewED25519Address(other.PublicKey())

// We first warm up the state we want to test
authFactory := tn.Configuration().AuthFactories()[0]
tx, err := tn.GenerateTx(context.Background(), []chain.Action{&actions.Transfer{
To: toAddress,
Value: 1,
Memo: []byte("warming up keys"),
}},
authFactory,
)
require.NoError(err)

timeoutCtx, timeoutCtxFnc := context.WithDeadline(context.Background(), time.Now().Add(30*time.Second))
defer timeoutCtxFnc()

// This call implicitly enforces that the state is warmed up by having the
// VM produce + accept a new block
require.NoError(tn.ConfirmTxs(timeoutCtx, []*chain.Transaction{tx}))

indexerCli := indexer.NewClient(tn.URIs()[0])
resp, success, err := indexerCli.GetTx(timeoutCtx, tx.GetID())
require.True(success)
require.NoError(err)
coldFee := resp.Fee

// If TX successful, state is now warmed up
// Now we can test the refund
tx, err = tn.GenerateTx(context.Background(), []chain.Action{&actions.Transfer{
To: toAddress,
Value: 1,
Memo: []byte("testing refunds"),
}},
authFactory,
)
require.NoError(err)

require.NoError(tn.ConfirmTxs(timeoutCtx, []*chain.Transaction{tx}))

queryCtx, queryCtxFnc := context.WithDeadline(context.Background(), time.Now().Add(30*time.Second))
defer queryCtxFnc()

resp, success, err = indexerCli.GetTx(queryCtx, tx.GetID())
require.NoError(err)
require.True(success)

require.Less(resp.Fee, coldFee)
})

0 comments on commit 5e619c4

Please sign in to comment.