diff --git a/test/features/composability/forwarder-raw/output/forwarder-raw-init-async-call.wasm b/test/features/composability/forwarder-raw/output/forwarder-raw-init-async-call.wasm index d8db3fd2e..39094691c 100755 Binary files a/test/features/composability/forwarder-raw/output/forwarder-raw-init-async-call.wasm and b/test/features/composability/forwarder-raw/output/forwarder-raw-init-async-call.wasm differ diff --git a/test/features/composability/forwarder-raw/output/forwarder-raw-init-sync-call.wasm b/test/features/composability/forwarder-raw/output/forwarder-raw-init-sync-call.wasm index 001bf0984..6233c5a49 100755 Binary files a/test/features/composability/forwarder-raw/output/forwarder-raw-init-sync-call.wasm and b/test/features/composability/forwarder-raw/output/forwarder-raw-init-sync-call.wasm differ diff --git a/test/features/composability/forwarder-raw/output/forwarder-raw.wasm b/test/features/composability/forwarder-raw/output/forwarder-raw.wasm index ed575905a..a3bd3052f 100755 Binary files a/test/features/composability/forwarder-raw/output/forwarder-raw.wasm and b/test/features/composability/forwarder-raw/output/forwarder-raw.wasm differ diff --git a/test/features/composability/forwarder/output/forwarder.wasm b/test/features/composability/forwarder/output/forwarder.wasm index dfd5b547a..0345789ea 100755 Binary files a/test/features/composability/forwarder/output/forwarder.wasm and b/test/features/composability/forwarder/output/forwarder.wasm differ diff --git a/test/features/composability/promises-features/output/promises-features.wasm b/test/features/composability/promises-features/output/promises-features.wasm index fcb20dceb..cb7225077 100755 Binary files a/test/features/composability/promises-features/output/promises-features.wasm and b/test/features/composability/promises-features/output/promises-features.wasm differ diff --git a/test/features/composability/proxy-test-first/output/proxy-test-first.wasm b/test/features/composability/proxy-test-first/output/proxy-test-first.wasm index 566ad44e7..0c43a7311 100755 Binary files a/test/features/composability/proxy-test-first/output/proxy-test-first.wasm and b/test/features/composability/proxy-test-first/output/proxy-test-first.wasm differ diff --git a/test/features/composability/proxy-test-second/output/proxy-test-second.wasm b/test/features/composability/proxy-test-second/output/proxy-test-second.wasm index e6c184f85..882461b36 100755 Binary files a/test/features/composability/proxy-test-second/output/proxy-test-second.wasm and b/test/features/composability/proxy-test-second/output/proxy-test-second.wasm differ diff --git a/test/features/composability/recursive-caller/output/recursive-caller.wasm b/test/features/composability/recursive-caller/output/recursive-caller.wasm index 0bfd743f9..58b0a2467 100755 Binary files a/test/features/composability/recursive-caller/output/recursive-caller.wasm and b/test/features/composability/recursive-caller/output/recursive-caller.wasm differ diff --git a/test/features/composability/scenarios-promises/forwarder_call_sync_retrieve_egld_bt.scen.json b/test/features/composability/scenarios-promises/forwarder_call_sync_retrieve_egld_bt.scen.json new file mode 100644 index 000000000..f552c8d0a --- /dev/null +++ b/test/features/composability/scenarios-promises/forwarder_call_sync_retrieve_egld_bt.scen.json @@ -0,0 +1,122 @@ +{ + "steps": [ + { + "step": "setState", + "accounts": { + "address:a_user": { + "nonce": "0", + "balance": "0" + }, + "sc:vault": { + "nonce": "0", + "balance": "1000", + "code": "file:../vault/output/vault.wasm" + }, + "sc:forwarder": { + "nonce": "0", + "balance": "0", + "code": "file:../promises-features/output/promises-features.wasm" + } + } + }, + { + "step": "scCall", + "id": "1", + "tx": { + "from": "address:a_user", + "to": "sc:forwarder", + "function": "forward_sync_retrieve_funds_bt", + "arguments": [ + "sc:vault", + "str:EGLD", + "0", + "1000" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [], + "status": "0", + "logs": [ + { + "address": "sc:forwarder", + "endpoint": "str:transferValueOnly", + "topics": [ + "0", + "sc:vault" + ], + "data": [ + "str:ExecuteOnDestContext", + "str:retrieve_funds", + "str:EGLD", + "0", + "1000" + ] + }, + { + "address": "sc:vault", + "endpoint": "str:retrieve_funds", + "topics": [ + "str:retrieve_funds", + "str:EGLD", + "0", + "1000" + ], + "data": [ + "" + ] + }, + { + "address": "sc:vault", + "endpoint": "str:transferValueOnly", + "topics": [ + "1000", + "sc:forwarder" + ], + "data": [ + "str:BackTransfer", + "0" + ] + }, + { + "address": "sc:forwarder", + "endpoint": "str:forward_sync_retrieve_funds_bt", + "topics": [ + "str:back_tranfers", + "1000" + ], + "data": [ + "" + ] + } + ], + "gas": "*", + "refund": "*" + } + }, + { + "step": "checkState", + "accounts": { + "address:a_user": { + "nonce": "*", + "balance": "0", + "storage": {}, + "code": "" + }, + "sc:vault": { + "nonce": "0", + "balance": "0", + "storage": {}, + "code": "file:../vault/output/vault.wasm" + }, + "sc:forwarder": { + "nonce": "0", + "balance": "1000", + "storage": "*", + "code": "file:../promises-features/output/promises-features.wasm" + } + } + } + ] +} diff --git a/test/features/composability/scenarios-promises/forwarder_call_sync_retrieve_esdt_bt.scen.json b/test/features/composability/scenarios-promises/forwarder_call_sync_retrieve_esdt_bt.scen.json new file mode 100644 index 000000000..da71e5375 --- /dev/null +++ b/test/features/composability/scenarios-promises/forwarder_call_sync_retrieve_esdt_bt.scen.json @@ -0,0 +1,135 @@ +{ + "steps": [ + { + "step": "setState", + "accounts": { + "address:a_user": { + "nonce": "0", + "balance": "0" + }, + "sc:vault": { + "nonce": "0", + "balance": "0", + "esdt": { + "str:TEST-TOKENA": "1000" + }, + "code": "file:../vault/output/vault.wasm" + }, + "sc:forwarder": { + "nonce": "0", + "balance": "0", + "code": "file:../promises-features/output/promises-features.wasm" + } + } + }, + { + "step": "scCall", + "id": "1", + "tx": { + "from": "address:a_user", + "to": "sc:forwarder", + "function": "forward_sync_retrieve_funds_bt", + "arguments": [ + "sc:vault", + "str:TEST-TOKENA", + "0", + "1000" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [], + "status": "0", + "logs": [ + { + "address": "sc:forwarder", + "endpoint": "str:transferValueOnly", + "topics": [ + "", + "sc:vault" + ], + "data": [ + "str:ExecuteOnDestContext", + "str:retrieve_funds", + "str:TEST-TOKENA", + "0", + "1000" + ] + }, + { + "address": "sc:vault", + "endpoint": "str:retrieve_funds", + "topics": [ + "str:retrieve_funds", + "str:TEST-TOKENA", + "0", + "1000" + ], + "data": [ + "" + ] + }, + { + "address": "sc:vault", + "endpoint": "str:ESDTTransfer", + "topics": [ + "str:TEST-TOKENA", + "0", + "1000", + "sc:forwarder" + ], + "data": [ + "str:BackTransfer", + "str:ESDTTransfer", + "str:TEST-TOKENA", + "1000" + ] + }, + { + "address": "sc:forwarder", + "endpoint": "str:forward_sync_retrieve_funds_bt", + "topics": [ + "str:back_tranfers", + "0", + "str:TEST-TOKENA", + "0", + "1000" + ], + "data": [ + "" + ] + } + ], + "gas": "*", + "refund": "*" + } + }, + { + "step": "checkState", + "accounts": { + "address:a_user": { + "nonce": "*", + "balance": "0", + "storage": {}, + "code": "" + }, + "sc:vault": { + "nonce": "0", + "balance": "0", + "storage": {}, + "code": "file:../vault/output/vault.wasm" + }, + "sc:forwarder": { + "nonce": "0", + "balance": "0", + "esdt": { + "str:TEST-TOKENA": "1000" + }, + "storage": "*", + "code": "file:../promises-features/output/promises-features.wasm" + } + } + } + ] +} diff --git a/test/features/composability/scenarios-promises/forwarder_call_sync_retrieve_nft_bt.scen.json b/test/features/composability/scenarios-promises/forwarder_call_sync_retrieve_nft_bt.scen.json new file mode 100644 index 000000000..a994117c0 --- /dev/null +++ b/test/features/composability/scenarios-promises/forwarder_call_sync_retrieve_nft_bt.scen.json @@ -0,0 +1,151 @@ +{ + "steps": [ + { + "step": "setState", + "accounts": { + "address:a_user": { + "nonce": "0", + "balance": "0" + }, + "sc:vault": { + "nonce": "0", + "balance": "0", + "esdt": { + "str:NFT-000001": { + "instances": [ + { + "nonce": "5", + "balance": "1" + } + ] + } + }, + "code": "file:../vault/output/vault.wasm" + }, + "sc:forwarder": { + "nonce": "0", + "balance": "0", + "code": "file:../promises-features/output/promises-features.wasm" + } + } + }, + { + "step": "scCall", + "id": "1", + "tx": { + "from": "address:a_user", + "to": "sc:forwarder", + "function": "forward_sync_retrieve_funds_bt", + "arguments": [ + "sc:vault", + "str:NFT-000001", + "5", + "1" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [], + "status": "0", + "logs": [ + { + "address": "sc:forwarder", + "endpoint": "str:transferValueOnly", + "topics": [ + "", + "sc:vault" + ], + "data": [ + "str:ExecuteOnDestContext", + "str:retrieve_funds", + "str:NFT-000001", + "5", + "01" + ] + }, + { + "address": "sc:vault", + "endpoint": "str:retrieve_funds", + "topics": [ + "str:retrieve_funds", + "str:NFT-000001", + "5", + "1" + ], + "data": [ + "" + ] + }, + { + "address": "sc:vault", + "endpoint": "str:ESDTNFTTransfer", + "topics": [ + "str:NFT-000001", + "5", + "01", + "sc:forwarder" + ], + "data": [ + "str:BackTransfer", + "str:ESDTNFTTransfer", + "str:NFT-000001", + "5", + "01", + "sc:forwarder" + ] + }, + { + "address": "sc:forwarder", + "endpoint": "str:forward_sync_retrieve_funds_bt", + "topics": [ + "str:back_tranfers", + "0", + "str:NFT-000001", + "5", + "1" + ], + "data": [ + "" + ] + } + ], + "gas": "*", + "refund": "*" + } + }, + { + "step": "checkState", + "accounts": { + "address:a_user": { + "nonce": "*", + "balance": "0", + "storage": {}, + "code": "" + }, + "sc:vault": { + "nonce": "0", + "balance": "0", + "storage": {}, + "code": "file:../vault/output/vault.wasm" + }, + "sc:forwarder": { + "nonce": "0", + "balance": "0", + "esdt": { + "str:NFT-000001": { + "instances": [ + { + "nonce": "5", + "balance": "1" + } + ] + } + }, + "storage": "*", + "code": "file:../promises-features/output/promises-features.wasm" + } + } + } + ] +} diff --git a/test/features/composability/scenarios-promises/promises_single_transfer.scen.json b/test/features/composability/scenarios-promises/promises_single_transfer.scen.json index ef3682880..8cc146229 100644 --- a/test/features/composability/scenarios-promises/promises_single_transfer.scen.json +++ b/test/features/composability/scenarios-promises/promises_single_transfer.scen.json @@ -75,8 +75,8 @@ "arguments": [ "sc:vault", "str:echo_arguments", - "3,000,000", - "100,000,000", + "10,000,000", + "10,000,000", "1", "2" ], diff --git a/test/features/composability/scenarios/forwarder_call_sync_retrieve_egld.scen.json b/test/features/composability/scenarios/forwarder_call_sync_retrieve_egld.scen.json index 38a45c7e2..436b7bf03 100644 --- a/test/features/composability/scenarios/forwarder_call_sync_retrieve_egld.scen.json +++ b/test/features/composability/scenarios/forwarder_call_sync_retrieve_egld.scen.json @@ -1,5 +1,4 @@ { - "gasSchedule": "v3", "steps": [ { "step": "setState", diff --git a/test/features/composability/scenarios/forwarder_call_sync_retrieve_esdt.scen.json b/test/features/composability/scenarios/forwarder_call_sync_retrieve_esdt.scen.json index 31ad91a9f..86b7aec65 100644 --- a/test/features/composability/scenarios/forwarder_call_sync_retrieve_esdt.scen.json +++ b/test/features/composability/scenarios/forwarder_call_sync_retrieve_esdt.scen.json @@ -1,5 +1,4 @@ { - "gasSchedule": "v3", "steps": [ { "step": "setState", diff --git a/test/features/composability/scenarios/forwarder_call_sync_retrieve_nft.scen.json b/test/features/composability/scenarios/forwarder_call_sync_retrieve_nft.scen.json index c326dbe98..0dc97972b 100644 --- a/test/features/composability/scenarios/forwarder_call_sync_retrieve_nft.scen.json +++ b/test/features/composability/scenarios/forwarder_call_sync_retrieve_nft.scen.json @@ -1,5 +1,4 @@ { - "gasSchedule": "v3", "steps": [ { "step": "setState", diff --git a/test/features/composability/vault/output/vault-promises.wasm b/test/features/composability/vault/output/vault-promises.wasm index 67a839149..a6c43b6ca 100755 Binary files a/test/features/composability/vault/output/vault-promises.wasm and b/test/features/composability/vault/output/vault-promises.wasm differ diff --git a/test/features/composability/vault/output/vault.wasm b/test/features/composability/vault/output/vault.wasm index 2f000efc4..291772c0a 100755 Binary files a/test/features/composability/vault/output/vault.wasm and b/test/features/composability/vault/output/vault.wasm differ diff --git a/vmhost/contexts/managedType.go b/vmhost/contexts/managedType.go index b26ebe089..37baf4ad3 100644 --- a/vmhost/contexts/managedType.go +++ b/vmhost/contexts/managedType.go @@ -5,13 +5,13 @@ import ( "crypto/elliptic" "encoding/binary" "errors" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" "io" basicMath "math" "math/big" "github.com/multiversx/mx-chain-core-go/core/check" logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-vm-go/math" "github.com/multiversx/mx-chain-vm-go/vmhost" ) @@ -552,7 +552,7 @@ func (context *managedTypesContext) NewManagedBufferFromBytes(bytes []byte) int3 return mBufferHandle } -// SetBytes sets the bytes given as value for the managed buffer +// SetBytes sets the bytes given as value for the managed buffer. Will create managed buffer if it doesn't exist. func (context *managedTypesContext) SetBytes(mBufferHandle int32, bytes []byte) { _, ok := context.managedTypesValues.mBufferValues[mBufferHandle] if !ok { diff --git a/vmhost/vmhooks/managedei.go b/vmhost/vmhooks/managedei.go index a6ffcf439..908bdc300 100644 --- a/vmhost/vmhooks/managedei.go +++ b/vmhost/vmhooks/managedei.go @@ -247,7 +247,7 @@ func (context *VMHooksImpl) ManagedGetMultiESDTCallValue(multiCallValueHandle in // ManagedGetBackTransfers VMHooks implementation. // @autogenerate(VMHooks) -func (context *VMHooksImpl) ManagedGetBackTransfers(esdtTransfersValueHandle int32, callValueHandle int32) { +func (context *VMHooksImpl) ManagedGetBackTransfers(esdtTransfersValueHandle int32, egldValueHandle int32) { metering := context.GetMeteringContext() managedType := context.GetManagedTypesContext() @@ -259,7 +259,8 @@ func (context *VMHooksImpl) ManagedGetBackTransfers(esdtTransfersValueHandle int managedType.ConsumeGasForBytes(multiCallBytes) managedType.SetBytes(esdtTransfersValueHandle, multiCallBytes) - managedType.SetBytes(callValueHandle, transferValue.Bytes()) + egldValue := managedType.GetBigIntOrCreate(egldValueHandle) + egldValue.SetBytes(transferValue.Bytes()) } // ManagedGetESDTBalance VMHooks implementation.