Skip to content

Commit

Permalink
Fix the counter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle authored and iFrostizz committed Apr 24, 2024
1 parent df3b46d commit 0be3d16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions x/programs/examples/counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func TestCounterProgram(t *testing.T) {
require.NoError(err)
require.Equal(int64(1), result[0])

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

// validate counter at 0
result, err = rt.Call(ctx, "get_value", callContext, alicePtr)
require.NoError(err)
Expand Down Expand Up @@ -129,11 +132,18 @@ func TestCounterProgram(t *testing.T) {
// increment alice's counter on program 2 by 10
incAmount := int64(10)
incAmountPtr, err := writeToMem(incAmount, mem2)
require.NoError(err)

alicePtr2, err = writeToMem(alicePublicKey, mem2)

require.NoError(err)
result, err = rt2.Call(ctx, "inc", callContext2, alicePtr2, incAmountPtr)
require.NoError(err)
require.Equal(int64(1), result[0])

alicePtr2, err = writeToMem(alicePublicKey, mem2)
require.NoError(err)

result, err = rt2.Call(ctx, "get_value", callContext2, alicePtr2)
require.NoError(err)
require.Equal(incAmount, result[0])
Expand All @@ -148,10 +158,17 @@ func TestCounterProgram(t *testing.T) {
// increment alice's counter on program 1
onePtr, err := writeToMem(int64(1), mem)
require.NoError(err)

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

result, err = rt.Call(ctx, "inc", callContext1, alicePtr, onePtr)
require.NoError(err)
require.Equal(int64(1), result[0])

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

result, err = rt.Call(ctx, "get_value", callContext1, alicePtr)
require.NoError(err)

Expand All @@ -170,10 +187,18 @@ func TestCounterProgram(t *testing.T) {
// increment alice's counter on program 2
fivePtr, err := writeToMem(int64(5), mem)
require.NoError(err)
alicePtr, err = writeToMem(alicePublicKey, mem)
require.NoError(err)
result, err = rt.Call(ctx, "inc_external", callContext1, target, maxUnitsProgramToProgramPtr, alicePtr, fivePtr)
require.NoError(err)
require.Equal(int64(1), result[0])

target, err = writeToMem(programID2, mem)
require.NoError(err)
alicePtr, err = writeToMem(alicePublicKey, mem)
require.NoError(err)
maxUnitsProgramToProgramPtr, err = writeToMem(maxUnitsProgramToProgram, mem)
require.NoError(err)
// expect alice's counter on program 2 to be 15
result, err = rt.Call(ctx, "get_value_external", callContext1, target, maxUnitsProgramToProgramPtr, alicePtr)
require.NoError(err)
Expand Down
Binary file modified x/programs/tests/fixture/counter.wasm
Binary file not shown.

0 comments on commit 0be3d16

Please sign in to comment.