Skip to content

Commit

Permalink
promise transfer no data example: ESDT/EGLD
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Jan 3, 2025
1 parent f4f588c commit 6ea4e86
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 16 deletions.
2 changes: 2 additions & 0 deletions chain/vm/src/vm_err_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ pub const ERROR_SIGNALLED_BY_SMARTCONTRACT: &str = "error signalled by smartcont

pub const ERROR_NO_CALLBACK_CLOSURE: &str =
"no callback for closure, cannot call callback directly";

pub const PROMISES_TOKENIZE_FAILED: &str = "tokenize failed";
6 changes: 6 additions & 0 deletions chain/vm/src/vm_hooks/vh_handler/vh_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
},
tx_mock::{AsyncCallTxData, Promise, TxFunctionName, TxTokenTransfer},
types::{top_encode_big_uint, top_encode_u64, RawHandle, VMAddress, VMCodeMetadata},
vm_err_msg,
vm_hooks::VMHooksHandlerSource,
};
use num_traits::Zero;
Expand Down Expand Up @@ -215,6 +216,11 @@ pub trait VMHooksSend: VMHooksHandlerSource {
let endpoint_name = self
.m_types_lock()
.mb_to_function_name(endpoint_name_handle);
if endpoint_name.is_empty() {
// immitating the behavior of the VM
// TODO: lift limitation from the VM, then also remove this condition here
self.vm_error(vm_err_msg::PROMISES_TOKENIZE_FAILED);
}
let arg_buffer = self.m_types_lock().mb_get_vec_of_bytes(arg_buffer_handle);
let tx_hash = self.tx_hash();
let callback_closure_data = self.m_types_lock().mb_get(callback_closure_handle).to_vec();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"steps": [
{
"step": "setState",
"accounts": {
"address:a_user": {
"nonce": "0",
"balance": "1000"
},
"sc:vault": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../vault/output/vault.mxsc.json"
},
"sc:forwarder": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../promises-features/output/promises-features.mxsc.json"
}
}
},
{
"step": "scCall",
"id": "1",
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"egldValue": "1000",
"function": "forward_payment_callback",
"arguments": [
"sc:vault"
],
"gasLimit": "60,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "10",
"message": "str:tokenize failed",
"gas": "*",
"refund": "*"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"accounts": {
"address:a_user": {
"nonce": "0",
"balance": "1000"
"balance": "0",
"esdt": {
"str:FWD-TOKEN": "1000"
}
},
"sc:vault": {
"nonce": "0",
Expand All @@ -25,7 +28,12 @@
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"egldValue": "1000",
"esdtValue": [
{
"tokenIdentifier": "str:FWD-TOKEN",
"value": "1000"
}
],
"function": "forward_payment_callback",
"arguments": [
"sc:vault"
Expand All @@ -39,22 +47,52 @@
"logs": [
{
"address": "sc:forwarder",
"endpoint": "str:transferValueOnly",
"endpoint": "str:ESDTTransfer",
"topics": [
"str:FWD-TOKEN",
"",
"1000",
"sc:vault"
],
"data": [
"str:AsyncCall",
"str:accept_funds"
"str:ESDTTransfer",
"str:FWD-TOKEN",
"1000"
]
},
{
"address": "sc:vault",
"endpoint": "str:accept_funds",
"endpoint": "str:transferValueOnly",
"topics": [
"str:accept_funds",
"1000"
"",
"sc:forwarder"
],
"data": [
"str:AsyncCallback",
"str:transfer_callback",
"0x00"
]
},
{
"address": "sc:forwarder",
"endpoint": "str:transfer_callback",
"topics": [
"str:callback_result",
"0x00"
],
"data": [
""
]
},
{
"address": "sc:forwarder",
"endpoint": "str:transfer_callback",
"topics": [
"str:retrieve_funds_callback",
"str:EGLD",
"",
""
],
"data": [
""
Expand All @@ -76,16 +114,29 @@
},
"sc:vault": {
"nonce": "0",
"balance": "1000",
"balance": "0",
"esdt": {
"str:FWD-TOKEN": "1000"
},
"storage": {
"str:call_counts|nested:str:accept_funds": "1"
"str:call_counts|nested:str:accept_funds": "0"
},
"code": "mxsc:../vault/output/vault.mxsc.json"
},
"sc:forwarder": {
"nonce": "0",
"balance": "0",
"storage": {},
"storage": {
"str:callback_data.len": "1",
"str:callback_data.item|u32:1": [
"nested:str:transfer_callback",
"nested:str:EGLD",
"u64:0",
"u32:0",
"u32:0"
]

},
"code": "mxsc:../promises-features/output/promises-features.mxsc.json"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,13 @@ fn promises_call_callback_directly_go() {
}

#[test]
#[ignore = "VM does not support this"]
fn promises_call_transfer_callback_go() {
world().run("scenarios/promises_call_transfer_callback.scen.json");
fn promises_call_transfer_callback_egld_go() {
world().run("scenarios/promises_call_transfer_callback_egld.scen.json");
}

#[test]
fn promises_call_transfer_callback_esdt_go() {
world().run("scenarios/promises_call_transfer_callback_esdt.scen.json");
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,13 @@ fn promises_call_callback_directly_rs() {
}

#[test]
#[ignore = "VM does not support this"]
fn promises_call_transfer_callback_rs() {
world().run("scenarios/promises_call_transfer_callback.scen.json");
fn promises_call_transfer_callback_egld_rs() {
world().run("scenarios/promises_call_transfer_callback_egld.scen.json");
}

#[test]
fn promises_call_transfer_callback_esdt_rs() {
world().run("scenarios/promises_call_transfer_callback_esdt.scen.json");
}

#[test]
Expand Down

0 comments on commit 6ea4e86

Please sign in to comment.