-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rc/v1.6.next1' into sandbox-queries
- Loading branch information
Showing
7 changed files
with
158 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+619 Bytes
integrationTests/vm/wasm/testdata/transferValue/output/transferValue.wasm
Binary file not shown.
58 changes: 58 additions & 0 deletions
58
integrationTests/vm/wasm/testdata/transferValue/transferValue.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
typedef unsigned char byte; | ||
typedef unsigned int i32; | ||
typedef unsigned long long i64; | ||
|
||
int getArgument(int argumentIndex, byte *argument); | ||
int transferValueExecute(byte *destination, byte *value, long long gas, byte *function, int functionLength, int numArguments, byte *argumentsLengths, byte *arguments); | ||
void getCaller(byte *callerAddress); | ||
i32 createAsyncCall(byte *destination, byte *value, byte *data, int dataLength, byte *success, int successLength, byte *error, int errorLength, long long gas, long long extraGasForCallback); | ||
|
||
byte zero32_a[32] = {0}; | ||
byte zero32_b[32] = {0}; | ||
byte zero32_c[32] = {0}; | ||
|
||
byte oneAtomOfEGLD[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, 1}; | ||
byte functionNameAskMoney[] = "askMoney"; | ||
byte functionNameMyCallback[] = "myCallback"; | ||
|
||
void init() | ||
{ | ||
} | ||
|
||
void upgrade() | ||
{ | ||
} | ||
|
||
void fund() | ||
{ | ||
} | ||
|
||
void forwardAskMoney() | ||
{ | ||
byte *otherContract = zero32_a; | ||
getArgument(0, otherContract); | ||
|
||
createAsyncCall( | ||
otherContract, | ||
0, | ||
functionNameAskMoney, | ||
sizeof(functionNameAskMoney) - 1, | ||
functionNameMyCallback, | ||
sizeof(functionNameMyCallback) - 1, | ||
functionNameMyCallback, | ||
sizeof(functionNameMyCallback) - 1, | ||
15000000, | ||
0); | ||
} | ||
|
||
void askMoney() | ||
{ | ||
byte *caller = zero32_a; | ||
|
||
getCaller(caller); | ||
transferValueExecute(caller, oneAtomOfEGLD, 0, 0, 0, 0, 0, 0); | ||
} | ||
|
||
void myCallback() | ||
{ | ||
} |
6 changes: 6 additions & 0 deletions
6
integrationTests/vm/wasm/testdata/transferValue/transferValue.export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
init | ||
upgrade | ||
fund | ||
forwardAskMoney | ||
askMoney | ||
myCallback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//go:build !race | ||
|
||
package transfers | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTransfers_DuplicatedTransferValueEvents(t *testing.T) { | ||
context := wasm.SetupTestContext(t) | ||
defer context.Close() | ||
|
||
err := context.DeploySC("../testdata/transferValue/output/transferValue.wasm", "") | ||
require.Nil(t, err) | ||
vault := context.ScAddress | ||
|
||
err = context.DeploySC("../testdata/transferValue/output/transferValue.wasm", "") | ||
require.Nil(t, err) | ||
forwarder := context.ScAddress | ||
|
||
// Add money to the vault | ||
context.ScAddress = vault | ||
err = context.ExecuteSCWithValue(&context.Owner, "fund", big.NewInt(42)) | ||
require.Nil(t, err) | ||
|
||
// Ask money from the vault, via the forwarder | ||
context.ScAddress = forwarder | ||
err = context.ExecuteSC(&context.Owner, fmt.Sprintf("forwardAskMoney@%s", hex.EncodeToString(vault))) | ||
require.Nil(t, err) | ||
require.Len(t, context.LastLogs, 1) | ||
require.Len(t, context.LastLogs[0].GetLogEvents(), 5) | ||
|
||
events := context.LastLogs[0].GetLogEvents() | ||
|
||
require.Equal(t, "transferValueOnly", string(events[0].GetIdentifier())) | ||
require.Equal(t, "AsyncCall", string(events[0].GetData())) | ||
require.Equal(t, []byte{}, events[0].GetTopics()[0]) | ||
require.Equal(t, forwarder, events[0].GetAddress()) | ||
require.Equal(t, vault, events[0].GetTopics()[1]) | ||
|
||
require.Equal(t, "transferValueOnly", string(events[1].GetIdentifier())) | ||
require.Equal(t, "BackTransfer", string(events[1].GetData())) | ||
require.Equal(t, []byte{0x01}, events[1].GetTopics()[0]) | ||
require.Equal(t, vault, events[1].GetAddress()) | ||
require.Equal(t, forwarder, events[1].GetTopics()[1]) | ||
|
||
// Duplicated "transferValueOnly" events are fixed in #5936. | ||
require.Equal(t, "transferValueOnly", string(events[2].GetIdentifier())) | ||
require.Equal(t, "AsyncCallback", string(events[2].GetData())) | ||
require.Equal(t, []byte{}, events[2].GetTopics()[0]) | ||
require.Equal(t, vault, events[2].GetAddress()) | ||
require.Equal(t, forwarder, events[2].GetTopics()[1]) | ||
|
||
require.Equal(t, "writeLog", string(events[3].GetIdentifier())) | ||
require.Equal(t, "completedTxEvent", string(events[4].GetIdentifier())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters