Skip to content

Commit

Permalink
fix token test
Browse files Browse the repository at this point in the history
  • Loading branch information
iFrostizz committed Apr 24, 2024
1 parent 0be3d16 commit d0cb8ad
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
50 changes: 50 additions & 0 deletions x/programs/examples/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ func (t *Token) Run(ctx context.Context) error {
zap.Int64("alice", mintAlice),
)

alicePtr, err = writeToMem(alicePublicKey, mem)
if err != nil {
return err
}

// check balance of alice
result, err = rt.Call(ctx, "get_balance", programContext, alicePtr)
if err != nil {
Expand All @@ -184,6 +189,11 @@ func (t *Token) Run(ctx context.Context) error {
zap.Int64("alice", result[0]),
)

bobPtr, err = writeToMem(bobPublicKey, mem)
if err != nil {
return err
}

// check balance of bob
result, err = rt.Call(ctx, "get_balance", programContext, bobPtr)
if err != nil {
Expand All @@ -199,6 +209,16 @@ func (t *Token) Run(ctx context.Context) error {
if err != nil {
return err
}
bobPtr, err = writeToMem(bobPublicKey, mem)
if err != nil {
return err
}

alicePtr, err = writeToMem(alicePublicKey, mem)
if err != nil {
return err
}

_, err = rt.Call(ctx, "transfer", programContext, alicePtr, bobPtr, transferToBobPtr)
if err != nil {
return err
Expand All @@ -213,6 +233,16 @@ func (t *Token) Run(ctx context.Context) error {
return err
}

bobPtr, err = writeToMem(bobPublicKey, mem)
if err != nil {
return err
}

alicePtr, err = writeToMem(alicePublicKey, mem)
if err != nil {
return err
}

_, err = rt.Call(ctx, "transfer", programContext, alicePtr, bobPtr, onePtr)
if err != nil {
return err
Expand All @@ -222,6 +252,11 @@ func (t *Token) Run(ctx context.Context) error {
zap.Int64("to bob", 1),
)

alicePtr, err = writeToMem(alicePublicKey, mem)
if err != nil {
return err
}

// get balance alice
result, err = rt.Call(ctx, "get_balance", programContext, alicePtr)
if err != nil {
Expand All @@ -231,6 +266,11 @@ func (t *Token) Run(ctx context.Context) error {
zap.Int64("alice", result[0]),
)

bobPtr, err = writeToMem(bobPublicKey, mem)
if err != nil {
return err
}

// get balance bob
result, err = rt.Call(ctx, "get_balance", programContext, bobPtr)
if err != nil {
Expand Down Expand Up @@ -274,6 +314,11 @@ func (t *Token) Run(ctx context.Context) error {
zap.Int32("to bob", minters[1].Amount),
)

alicePtr, err = writeToMem(alicePublicKey, mem)
if err != nil {
return err
}

// get balance alice
result, err = rt.Call(ctx, "get_balance", programContext, alicePtr)
if err != nil {
Expand All @@ -283,6 +328,11 @@ func (t *Token) Run(ctx context.Context) error {
zap.Int64("alice", result[0]),
)

bobPtr, err = writeToMem(bobPublicKey, mem)
if err != nil {
return err
}

// get balance bob
result, err = rt.Call(ctx, "get_balance", programContext, bobPtr)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions x/programs/examples/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func TestTokenProgram(t *testing.T) {
_, err = rt.Call(ctx, "mint_to", callContext, alicePtr, mintAlicePtr)
require.NoError(err)

alicePtr, err = writeToMem(alicePublicKey, mem)
require.NoError(err)

// check balance of alice
result, err := rt.Call(ctx, "get_balance", callContext, alicePtr)
require.NoError(err)
Expand All @@ -75,6 +78,9 @@ func TestTokenProgram(t *testing.T) {
require.NoError(err)
require.Equal(int64(1000), aliceBalance)

alicePtr, err = writeToMem(alicePublicKey, mem)
require.NoError(err)

// burn alice tokens
_, err = rt.Call(ctx, "burn_from", callContext, alicePtr)
require.NoError(err)
Expand Down
Binary file modified x/programs/tests/fixture/token.wasm
Binary file not shown.

0 comments on commit d0cb8ad

Please sign in to comment.