Skip to content

Commit 79ba93a

Browse files
Merge pull request #1981 from multiversx/bitflag-typeabi
typeabi bitflag - test
2 parents 3a77729 + cf5fed3 commit 79ba93a

File tree

18 files changed

+454
-172
lines changed

18 files changed

+454
-172
lines changed

Cargo.lock

Lines changed: 159 additions & 123 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/feature-tests/abi-tester/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ path = "../../../framework/scenario"
2020
[dev-dependencies.multiversx-sc-meta-lib]
2121
version = "0.56.1"
2222
path = "../../../framework/meta-lib"
23+
24+
[dependencies]
25+
bitflags = "=2.8.0"

contracts/feature-tests/abi-tester/abi_tester_expected_main.abi.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,21 @@
332332
}
333333
]
334334
},
335+
{
336+
"name": "echo_permission",
337+
"mutability": "readonly",
338+
"inputs": [
339+
{
340+
"name": "p",
341+
"type": "Permission"
342+
}
343+
],
344+
"outputs": [
345+
{
346+
"type": "Permission"
347+
}
348+
]
349+
},
335350
{
336351
"name": "item_for_array",
337352
"mutability": "readonly",
@@ -1021,6 +1036,15 @@
10211036
"name": "interrupted"
10221037
}
10231038
]
1039+
},
1040+
"Permission": {
1041+
"type": "struct",
1042+
"fields": [
1043+
{
1044+
"name": "0",
1045+
"type": "u32"
1046+
}
1047+
]
10241048
}
10251049
}
10261050
}

contracts/feature-tests/abi-tester/abi_tester_expected_view.abi.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,15 @@
641641
"name": "interrupted"
642642
}
643643
]
644+
},
645+
"Permission": {
646+
"type": "struct",
647+
"fields": [
648+
{
649+
"name": "0",
650+
"type": "u32"
651+
}
652+
]
644653
}
645654
}
646655
}

contracts/feature-tests/abi-tester/src/abi_proxy.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,19 @@ where
312312
.original_result()
313313
}
314314

315+
pub fn echo_permission<
316+
Arg0: ProxyArg<Permission>,
317+
>(
318+
self,
319+
p: Arg0,
320+
) -> TxTypedCall<Env, From, To, NotPayable, Gas, Permission> {
321+
self.wrapped_tx
322+
.payment(NotPayable)
323+
.raw_call("echo_permission")
324+
.argument(&p)
325+
.original_result()
326+
}
327+
315328
pub fn item_for_array<
316329
Arg0: ProxyArg<[OnlyShowsUpAsNestedInArray; 5]>,
317330
>(
@@ -520,6 +533,10 @@ pub struct AbiManagedVecItem {
520533
pub value2: u32,
521534
}
522535

536+
#[type_abi]
537+
#[derive(Clone, Copy, Debug, PartialEq, Eq, NestedDecode, NestedEncode, TopEncode, TopDecode)]
538+
pub struct Permission(u32);
539+
523540
#[type_abi]
524541
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
525542
pub struct OnlyShowsUpAsNestedInArray {}

contracts/feature-tests/abi-tester/src/abi_test_type.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::only_nested::*;
2+
use bitflags::bitflags;
23
use multiversx_sc::{
34
api::ManagedTypeApi,
45
typenum::U2,
@@ -60,3 +61,14 @@ pub struct AbiWithManagedBufferReadToEnd<M: ManagedTypeApi> {
6061
pub gas: u64,
6162
pub flush: ManagedBufferReadToEnd<M>,
6263
}
64+
65+
bitflags! {
66+
#[type_abi]
67+
#[derive(Clone, Copy, Debug, PartialEq, Eq, NestedDecode, NestedEncode, TopEncode, TopDecode)]
68+
pub struct Permission: u32 {
69+
const NONE = 0;
70+
const OWNER = 1;
71+
const ADMIN = 2;
72+
const PAUSE = 4;
73+
}
74+
}

contracts/feature-tests/abi-tester/src/abi_tester.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ pub trait AbiTester {
152152
ManagedVec::new()
153153
}
154154

155+
#[view]
156+
fn echo_permission(&self, p: Permission) -> Permission {
157+
p
158+
}
159+
155160
#[view]
156161
fn item_for_array(&self, _array: &[OnlyShowsUpAsNestedInArray; 5]) {}
157162

contracts/feature-tests/abi-tester/wasm-abi-tester-ev/Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/feature-tests/abi-tester/wasm-abi-tester/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/feature-tests/abi-tester/wasm-abi-tester/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
// Init: 1
88
// Upgrade: 1
9-
// Endpoints: 30
9+
// Endpoints: 31
1010
// Async Callback (empty): 1
11-
// Total number of exported functions: 33
11+
// Total number of exported functions: 34
1212

1313
#![no_std]
1414

@@ -39,6 +39,7 @@ multiversx_sc_wasm_adapter::endpoints! {
3939
item_for_vec => item_for_vec
4040
item_for_array_vec => item_for_array_vec
4141
item_for_managed_vec => item_for_managed_vec
42+
echo_permission => echo_permission
4243
item_for_array => item_for_array
4344
item_for_box => item_for_box
4445
item_for_boxed_slice => item_for_boxed_slice

0 commit comments

Comments
 (0)