Skip to content

Commit a89768e

Browse files
Merge pull request #2256 from multiversx/egld-000000-tests
more payable-features tests
2 parents d29bc5e + 8fef8c8 commit a89768e

File tree

11 files changed

+286
-36
lines changed

11 files changed

+286
-36
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
{
2+
"name": "payable",
3+
"steps": [
4+
{
5+
"step": "setState",
6+
"accounts": {
7+
"sc:payable-features": {
8+
"nonce": "0",
9+
"balance": "0",
10+
"code": "mxsc:../output/payable-features.mxsc.json"
11+
},
12+
"address:an-account": {
13+
"nonce": "0",
14+
"balance": "10000",
15+
"esdt": {
16+
"str:TOK-123456": "1000",
17+
"str:OTHERTOK-123456": "500",
18+
"str:SFT-123": {
19+
"instances": [
20+
{
21+
"nonce": "5",
22+
"balance": "20"
23+
}
24+
]
25+
}
26+
}
27+
}
28+
}
29+
},
30+
{
31+
"step": "scCall",
32+
"id": "payable_all-ZERO",
33+
"tx": {
34+
"from": "address:an-account",
35+
"to": "sc:payable-features",
36+
"function": "payable_all",
37+
"arguments": [],
38+
"gasLimit": "50,000,000",
39+
"gasPrice": "0"
40+
},
41+
"expect": {
42+
"out": [
43+
""
44+
],
45+
"status": "",
46+
"logs": "*",
47+
"gas": "*",
48+
"refund": "*"
49+
}
50+
},
51+
{
52+
"step": "scCall",
53+
"id": "payable_all-EGLD",
54+
"tx": {
55+
"from": "address:an-account",
56+
"to": "sc:payable-features",
57+
"egldValue": "1000",
58+
"function": "payable_all",
59+
"arguments": [],
60+
"gasLimit": "50,000,000",
61+
"gasPrice": "0"
62+
},
63+
"expect": {
64+
"out": [
65+
[
66+
"nested:str:EGLD-000000|u64:0|biguint:1000"
67+
]
68+
],
69+
"status": "",
70+
"logs": "*",
71+
"gas": "*",
72+
"refund": "*"
73+
}
74+
},
75+
{
76+
"step": "scCall",
77+
"id": "payable_all-multi-EGLD-2",
78+
"tx": {
79+
"from": "address:an-account",
80+
"to": "sc:payable-features",
81+
"esdtValue": [
82+
{
83+
"tokenIdentifier": "str:EGLD-000000",
84+
"value": "1001"
85+
},
86+
{
87+
"tokenIdentifier": "str:EGLD-000000",
88+
"value": "1002"
89+
}
90+
],
91+
"function": "payable_all",
92+
"arguments": [],
93+
"gasLimit": "50,000,000",
94+
"gasPrice": "0"
95+
},
96+
"expect": {
97+
"out": [
98+
[
99+
"nested:str:EGLD-000000|u64:0|biguint:1001",
100+
"nested:str:EGLD-000000|u64:0|biguint:1002"
101+
]
102+
],
103+
"status": "",
104+
"logs": "*",
105+
"gas": "*",
106+
"refund": "*"
107+
}
108+
},
109+
{
110+
"step": "scCall",
111+
"id": "payable_all-EGLD-with-ESDT",
112+
"tx": {
113+
"from": "address:an-account",
114+
"to": "sc:payable-features",
115+
"esdtValue": [
116+
{
117+
"tokenIdentifier": "str:TOK-123456",
118+
"value": "100"
119+
},
120+
{
121+
"tokenIdentifier": "str:EGLD-000000",
122+
"value": "1005"
123+
},
124+
{
125+
"tokenIdentifier": "str:OTHERTOK-123456",
126+
"value": "400"
127+
},
128+
{
129+
"tokenIdentifier": "str:SFT-123",
130+
"nonce": "5",
131+
"value": "10"
132+
},
133+
{
134+
"tokenIdentifier": "str:EGLD-000000",
135+
"value": "1006"
136+
}
137+
],
138+
"function": "payable_all",
139+
"arguments": [],
140+
"gasLimit": "50,000,000",
141+
"gasPrice": "0"
142+
},
143+
"expect": {
144+
"out": [
145+
[
146+
"nested:str:TOK-123456|u64:0|biguint:100|",
147+
"nested:str:EGLD-000000|u64:0|biguint:1005",
148+
"nested:str:OTHERTOK-123456|u64:0|biguint:400",
149+
"nested:str:SFT-123|u64:5|biguint:10",
150+
"nested:str:EGLD-000000|u64:0|biguint:1006"
151+
]
152+
],
153+
"status": "",
154+
"logs": "*",
155+
"gas": "*",
156+
"refund": "*"
157+
}
158+
}
159+
]
160+
}

contracts/feature-tests/payable-features/scenarios/call-value-check-multi-egld.scen.json renamed to contracts/feature-tests/payable-features/scenarios/payable_all_2.scen.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
{
3030
"step": "scCall",
31-
"id": "call-value-multi-egld-esdt",
31+
"id": "payable_all",
3232
"tx": {
3333
"from": "address:an-account",
3434
"to": "sc:payable-features",
@@ -51,7 +51,7 @@
5151
"value": "10"
5252
}
5353
],
54-
"function": "echo_call_value",
54+
"function": "payable_all",
5555
"arguments": [],
5656
"gasLimit": "50,000,000",
5757
"gasPrice": "0"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"steps": [
3+
{
4+
"step": "setState",
5+
"accounts": {
6+
"address:a_user": {
7+
"nonce": "0",
8+
"balance": "100",
9+
"esdt": {
10+
"str:TOK-123456": "100"
11+
}
12+
},
13+
"sc:payable": {
14+
"nonce": "0",
15+
"balance": "0",
16+
"code": "mxsc:../output/payable-features.mxsc.json"
17+
}
18+
}
19+
},
20+
{
21+
"step": "scCall",
22+
"id": "",
23+
"tx": {
24+
"from": "address:a_user",
25+
"to": "sc:payable",
26+
"esdtValue": [
27+
{
28+
"tokenIdentifier": "str:EGLD-000000",
29+
"value": "10"
30+
}
31+
],
32+
"function": "payable_all",
33+
"arguments": [],
34+
"gasLimit": "6000000"
35+
},
36+
"expect": {
37+
"out": [
38+
[
39+
"nested:str:EGLD-000000|u64:0|biguint:10"
40+
]
41+
],
42+
"status": "",
43+
"logs": "*",
44+
"gas": "*",
45+
"refund": "*"
46+
}
47+
},
48+
{
49+
"step": "checkState",
50+
"accounts": {
51+
"address:a_user": {
52+
"nonce": "*",
53+
"balance": "90",
54+
"storage": {},
55+
"esdt": {
56+
"str:TOK-123456": "100"
57+
},
58+
"code": ""
59+
},
60+
"sc:payable": {
61+
"nonce": "0",
62+
"balance": "10",
63+
"storage": {},
64+
"esdt": {},
65+
"code": "mxsc:../output/payable-features.mxsc.json"
66+
}
67+
}
68+
}
69+
]
70+
}

contracts/feature-tests/payable-features/scenarios/call-value-check.scen.json renamed to contracts/feature-tests/payable-features/scenarios/payable_legacy_egld_esdt.scen.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
},
2929
{
3030
"step": "scCall",
31-
"id": "echo_call_value_legacy",
31+
"id": "payable_legacy_egld_esdt",
3232
"tx": {
3333
"from": "address:an-account",
3434
"to": "sc:payable-features",
3535
"egldValue": "100",
36-
"function": "echo_call_value_legacy",
36+
"function": "payable_legacy_egld_esdt",
3737
"arguments": [],
3838
"gasLimit": "50,000,000",
3939
"gasPrice": "0"
@@ -61,7 +61,7 @@
6161
"value": "100"
6262
}
6363
],
64-
"function": "echo_call_value_legacy",
64+
"function": "payable_legacy_egld_esdt",
6565
"arguments": [],
6666
"gasLimit": "50,000,000",
6767
"gasPrice": "0"
@@ -100,7 +100,7 @@
100100
"value": "10"
101101
}
102102
],
103-
"function": "echo_call_value_legacy",
103+
"function": "payable_legacy_egld_esdt",
104104
"arguments": [],
105105
"gasLimit": "50,000,000",
106106
"gasPrice": "0"

contracts/feature-tests/payable-features/src/payable_features.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,14 @@ pub trait PayableFeatures {
1414

1515
#[view]
1616
#[payable("*")]
17-
fn echo_call_value_legacy(&self) -> MultiValue2<BigUint, ManagedVec<EsdtTokenPayment>> {
17+
fn payable_legacy_egld_esdt(&self) -> MultiValue2<BigUint, ManagedVec<EsdtTokenPayment>> {
1818
(
1919
self.call_value().egld_direct_non_strict().clone_value(),
2020
self.call_value().all_esdt_transfers().clone_value(),
2121
)
2222
.into()
2323
}
2424

25-
#[view]
26-
#[payable("*")]
27-
fn echo_call_value(&self) -> ManagedVec<Payment> {
28-
self.call_value().all().clone()
29-
}
30-
3125
#[endpoint]
3226
#[payable("*")]
3327
fn payment_multiple(
@@ -43,6 +37,12 @@ pub trait PayableFeatures {
4337
self.call_value().all_transfers().clone()
4438
}
4539

40+
#[endpoint]
41+
#[payable("*")]
42+
fn payable_all(&self) -> ManagedVec<Payment> {
43+
self.call_value().all().clone()
44+
}
45+
4646
#[endpoint]
4747
#[payable("*")]
4848
fn payment_array_esdt_3(

contracts/feature-tests/payable-features/src/payable_features_proxy.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,11 @@ where
6262
To: TxTo<Env>,
6363
Gas: TxGas<Env>,
6464
{
65-
pub fn echo_call_value_legacy(
65+
pub fn payable_legacy_egld_esdt(
6666
self,
6767
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, ManagedVec<Env::Api, EsdtTokenPayment<Env::Api>>>> {
6868
self.wrapped_tx
69-
.raw_call("echo_call_value_legacy")
70-
.original_result()
71-
}
72-
73-
pub fn echo_call_value(
74-
self,
75-
) -> TxTypedCall<Env, From, To, (), Gas, ManagedVec<Env::Api, Payment<Env::Api>>> {
76-
self.wrapped_tx
77-
.raw_call("echo_call_value")
69+
.raw_call("payable_legacy_egld_esdt")
7870
.original_result()
7971
}
8072

@@ -94,6 +86,14 @@ where
9486
.original_result()
9587
}
9688

89+
pub fn payable_all(
90+
self,
91+
) -> TxTypedCall<Env, From, To, (), Gas, ManagedVec<Env::Api, Payment<Env::Api>>> {
92+
self.wrapped_tx
93+
.raw_call("payable_all")
94+
.original_result()
95+
}
96+
9797
pub fn payment_array_esdt_3(
9898
self,
9999
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue3<EsdtTokenPayment<Env::Api>, EsdtTokenPayment<Env::Api>, EsdtTokenPayment<Env::Api>>> {

contracts/feature-tests/payable-features/tests/payable_blackbox_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn payable_multi_legacy() {
4343
.from(USER)
4444
.to(PAYABLE_FEATURES_ADDRESS)
4545
.typed(payable_features_proxy::PayableFeaturesProxy)
46-
.echo_call_value_legacy()
46+
.payable_legacy_egld_esdt()
4747
.esdt(TestEsdtTransfer(TOKEN_1, 0, 100))
4848
.esdt(TestEsdtTransfer(TOKEN_2, 0, 400))
4949
.returns(ReturnsResultUnmanaged)

contracts/feature-tests/payable-features/tests/payable_scenario_go_test.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ fn world() -> ScenarioWorld {
55
}
66

77
#[test]
8-
fn call_value_check_go() {
9-
world().run("scenarios/call-value-check.scen.json");
8+
fn payable_all_1_go() {
9+
world().run("scenarios/payable_all_1.scen.json");
1010
}
1111

1212
#[test]
13-
fn call_value_check_multi_egld_go() {
14-
world().run("scenarios/call-value-check-multi-egld.scen.json");
13+
fn payable_all_2_go() {
14+
world().run("scenarios/payable_all_2.scen.json");
15+
}
16+
17+
#[test]
18+
fn payable_all_3_go() {
19+
world().run("scenarios/payable_all_3.scen.json");
1520
}
1621

1722
#[test]
@@ -89,6 +94,11 @@ fn payable_egld_5_go() {
8994
world().run("scenarios/payable_egld_5.scen.json");
9095
}
9196

97+
#[test]
98+
fn payable_legacy_egld_esdt_go() {
99+
world().run("scenarios/payable_legacy_egld_esdt.scen.json");
100+
}
101+
92102
#[test]
93103
fn payable_multiple_go() {
94104
world().run("scenarios/payable_multiple.scen.json");

0 commit comments

Comments
 (0)