Skip to content

Commit

Permalink
Improve tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Apr 15, 2024
1 parent 1861088 commit e4dfe68
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 37 deletions.
27 changes: 17 additions & 10 deletions integrationTests/vm/wasm/developerRewards/developerRewards_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package transfers

import (
"math/big"
"testing"

"github.com/multiversx/mx-chain-go/integrationTests/vm/wasm"
Expand All @@ -13,20 +12,22 @@ func TestClaimDeveloperRewards(t *testing.T) {
t.Skip("this is not a short test")
}

context := wasm.SetupTestContext(t)
defer context.Close()

err := context.DeploySC("../testdata/developer-rewards/output/developer_rewards.wasm", "")
require.Nil(t, err)
wasmPath := "../testdata/developer-rewards/output/developer_rewards.wasm"

t.Run("rewards for user", func(t *testing.T) {
context := wasm.SetupTestContext(t)
defer context.Close()

err := context.DeploySC(wasmPath, "")
require.Nil(t, err)
contractAddress := context.ScAddress

err = context.ExecuteSC(&context.Owner, "doSomething")
require.Nil(t, err)

ownerBalanceBefore := context.GetAccountBalance(&context.Owner).Uint64()
reward := context.GetAccount(contractAddress).GetDeveloperReward().Uint64()
rewardBig := context.GetAccount(contractAddress).GetDeveloperReward()
reward := rewardBig.Uint64()

err = context.ExecuteSC(&context.Owner, "ClaimDeveloperRewards")
require.Nil(t, err)
Expand All @@ -36,11 +37,16 @@ func TestClaimDeveloperRewards(t *testing.T) {

events := context.LastLogs[0].GetLogEvents()
require.Equal(t, "ClaimDeveloperRewards", string(events[0].GetIdentifier()))
require.Equal(t, big.NewInt(0).SetUint64(reward).Bytes(), events[0].GetTopics()[0])
require.Equal(t, rewardBig.Bytes(), events[0].GetTopics()[0])
require.Equal(t, context.Owner.Address, events[0].GetTopics()[1])
})

t.Run("rewards for contract", func(t *testing.T) {
context := wasm.SetupTestContext(t)
defer context.Close()

err := context.DeploySC(wasmPath, "")
require.Nil(t, err)
parentContractAddress := context.ScAddress

err = context.ExecuteSC(&context.Owner, "deployChild")
Expand All @@ -54,7 +60,8 @@ func TestClaimDeveloperRewards(t *testing.T) {
require.Nil(t, err)

contractBalanceBefore := context.GetAccount(parentContractAddress).GetBalance().Uint64()
reward := context.GetAccount(chilContractdAddress).GetDeveloperReward().Uint64()
rewardBig := context.GetAccount(chilContractdAddress).GetDeveloperReward()
reward := rewardBig.Uint64()

context.ScAddress = parentContractAddress
err = context.ExecuteSC(&context.Owner, "claimDeveloperRewardsOnChild")
Expand All @@ -65,7 +72,7 @@ func TestClaimDeveloperRewards(t *testing.T) {

events := context.LastLogs[0].GetLogEvents()
require.Equal(t, "ClaimDeveloperRewards", string(events[0].GetIdentifier()))
require.Equal(t, big.NewInt(0).SetUint64(reward).Bytes(), events[0].GetTopics()[0])
require.Equal(t, rewardBig.Bytes(), events[0].GetTopics()[0])
require.Equal(t, parentContractAddress, events[0].GetTopics()[1])
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ static const i32 ADDRESS_LENGTH = 32;

byte zero32_red[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte zero32_green[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte zero32_blue[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

// E.g. can hold up to 64 addresses.
byte zero2048_red[2048] = {0};
byte zero2048_green[2048] = {0};
byte zero2048_blue[2048] = {0};

byte zeroEGLD[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Expand All @@ -48,7 +42,6 @@ byte codeMetadataUpgradeableReadable[2] = {5, 0};
byte emptyArguments[0] = {};
int emptyArgumentsLengths[0] = {};
int gasLimitDeploySelf = 20000000;
int gasLimitUpgradeChild = 20000000;
int gasLimitClaimDeveloperRewards = 6000000;

byte functionNameClaimDeveloperRewards[] = "ClaimDeveloperRewards";
Expand All @@ -72,7 +65,7 @@ void doSomething()
void deployChild()
{
byte *selfAddress = zero32_red;
byte *newAddress = zero32_blue;
byte *newAddress = zero32_green;

getSCAddress(selfAddress);

Expand All @@ -96,24 +89,6 @@ void getChildAddress()
finish(childAddress, ADDRESS_LENGTH);
}

void callChild()
{
byte *childAddress = zero32_red;
storageLoad(storageKeyChildAddress, sizeof(storageKeyChildAddress) - 1, childAddress);

createAsyncCall(
childAddress,
zeroEGLD,
functionNameDoSomething,
sizeof(functionNameDoSomething) - 1,
0,
0,
0,
0,
15000000,
0);
}

void claimDeveloperRewardsOnChild()
{
byte *childAddress = zero32_red;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ upgrade
doSomething
deployChild
getChildAddress
callChild
claimDeveloperRewardsOnChild
Binary file not shown.

0 comments on commit e4dfe68

Please sign in to comment.