From 2e95bd35d3f97acdfba7e43035494db19f1c1549 Mon Sep 17 00:00:00 2001 From: Ovidiu Stinga Date: Wed, 5 Jul 2023 13:06:31 +0300 Subject: [PATCH 1/3] add cli for issue nft with all roles and new trace for scenarios --- .../interact-rs/src/multisig_interact.rs | 8 + .../interact-rs/src/multisig_interact_cli.rs | 10 + .../interact-rs/src/multisig_interact_nfts.rs | 89 +++ .../interactor_nft_all_roles.scen.json | 526 ++++++++++++++++++ .../tests/multisig_scenario_go_test.rs | 37 +- .../tests/multisig_scenario_rs_test.rs | 37 +- 6 files changed, 675 insertions(+), 32 deletions(-) create mode 100644 contracts/examples/multisig/scenarios/interactor_nft_all_roles.scen.json diff --git a/contracts/examples/multisig/interact-rs/src/multisig_interact.rs b/contracts/examples/multisig/interact-rs/src/multisig_interact.rs index 289ac3ade2..f5e79795f0 100644 --- a/contracts/examples/multisig/interact-rs/src/multisig_interact.rs +++ b/contracts/examples/multisig/interact-rs/src/multisig_interact.rs @@ -58,9 +58,17 @@ async fn main() { Some(multisig_interact_cli::InteractCliCommand::MultiDeploy(args)) => { multisig_interact.multi_deploy(&args.count).await; }, + Some(multisig_interact_cli::InteractCliCommand::NftFullAllRoles) => { + multisig_interact + .issue_multisig_and_collection_with_all_roles_full() + .await; + }, Some(multisig_interact_cli::InteractCliCommand::NftFull) => { multisig_interact.issue_multisig_and_collection_full().await; }, + Some(multisig_interact_cli::InteractCliCommand::NftIssueAllRoles) => { + multisig_interact.issue_collection_with_all_roles().await; + }, Some(multisig_interact_cli::InteractCliCommand::NftIssue) => { multisig_interact.issue_collection().await; }, diff --git a/contracts/examples/multisig/interact-rs/src/multisig_interact_cli.rs b/contracts/examples/multisig/interact-rs/src/multisig_interact_cli.rs index e2a67a199a..49c7f21d82 100644 --- a/contracts/examples/multisig/interact-rs/src/multisig_interact_cli.rs +++ b/contracts/examples/multisig/interact-rs/src/multisig_interact_cli.rs @@ -22,8 +22,18 @@ pub enum InteractCliCommand { Feed, #[command(name = "multi-deploy", about = "Multiple deploy contracts")] MultiDeploy(MultiDeployArgs), + #[command( + name = "nft-full-all-roles", + about = "Issue multisig and collection with all roles" + )] + NftFullAllRoles, #[command(name = "nft-full", about = "Issue multisig and collection")] NftFull, + #[command( + name = "nft-issue-all-roles", + about = "Issue collection with all roles" + )] + NftIssueAllRoles, #[command(name = "nft-issue", about = "Issue collection")] NftIssue, #[command(name = "nft-items", about = "Create items")] diff --git a/contracts/examples/multisig/interact-rs/src/multisig_interact_nfts.rs b/contracts/examples/multisig/interact-rs/src/multisig_interact_nfts.rs index df7ab0c1ad..ebb6c4f85f 100644 --- a/contracts/examples/multisig/interact-rs/src/multisig_interact_nfts.rs +++ b/contracts/examples/multisig/interact-rs/src/multisig_interact_nfts.rs @@ -8,6 +8,7 @@ const ISSUE_COST: u64 = 50000000000000000; // 0.05 EGLD const COLLECTION_NAME: &str = "TestCollection1"; const COLLECTION_TICKER: &str = "TESTCOLL1"; +const TOKEN_TYPE: &str = "NFT"; const NUM_ITEMS: usize = 3; const ROYALTIES: usize = 3000; @@ -23,6 +24,94 @@ impl MultisigInteract { self.create_items().await; } + pub async fn issue_multisig_and_collection_with_all_roles_full(&mut self) { + self.deploy().await; + self.feed_contract_egld().await; + self.issue_collection_with_all_roles().await; + self.interactor.sleep(Duration::from_secs(15)).await; + self.create_items().await; + } + + pub async fn propose_issue_collection_with_all_roles(&mut self) -> Option { + let system_sc_address = bech32::decode(SYSTEM_SC_BECH32); + let mut typed_sc_call = self + .state + .multisig() + .propose_async_call( + system_sc_address, + ISSUE_COST, + "registerAndSetAllRoles".to_string(), + MultiValueVec::from([ + COLLECTION_NAME.as_bytes(), + COLLECTION_TICKER.as_bytes(), + TOKEN_TYPE.as_bytes(), + top_encode_to_vec_u8_or_panic(&0u32).as_slice(), + ]), + ) + .into_blockchain_call() + .from(&self.wallet_address) + .gas_limit("10,000,000") + .expect(TxExpect::ok()); + + self.interactor.sc_call(&mut typed_sc_call).await; + + let result = typed_sc_call.result(); + if result.is_err() { + println!( + "propose issue collection with roles failed with: {}", + result.err().unwrap() + ); + return None; + } + + let action_id = result.unwrap(); + println!("successfully proposed issue colllection with roles action `{action_id}`"); + Some(action_id) + } + + pub async fn issue_collection_with_all_roles(&mut self) { + println!("proposing issue collection with all roles..."); + let action_id = self.propose_issue_collection_with_all_roles().await; + if action_id.is_none() { + return; + } + + let action_id = action_id.unwrap(); + println!("perfoming issue collection with all roles action `{action_id}`..."); + + if !self.quorum_reached(action_id).await && !self.sign(action_id).await { + return; + } + println!("quorum reached for action `{action_id}`"); + + let mut typed_sc_call = self + .state + .multisig() + .perform_action_endpoint(action_id) + .into_blockchain_call() + .from(&self.wallet_address) + .gas_limit("80,000,000"); + + self.interactor.sc_call(&mut typed_sc_call).await; + + let result = typed_sc_call + .response() + .issue_non_fungible_new_token_identifier(); + if result.is_err() { + println!( + "perform issue collection with all roles failed with: {}", + result.err().unwrap() + ); + return; + } + + self.collection_token_identifier = result.unwrap(); + println!( + "collection token identifier: {}", + self.collection_token_identifier + ); + } + pub async fn propose_issue_collection(&mut self) -> Option { let system_sc_address = bech32::decode(SYSTEM_SC_BECH32); let mut typed_sc_call = self diff --git a/contracts/examples/multisig/scenarios/interactor_nft_all_roles.scen.json b/contracts/examples/multisig/scenarios/interactor_nft_all_roles.scen.json new file mode 100644 index 0000000000..8746f7fba9 --- /dev/null +++ b/contracts/examples/multisig/scenarios/interactor_nft_all_roles.scen.json @@ -0,0 +1,526 @@ +{ + "steps": [ + { + "step": "setState", + "accounts": { + "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60": { + "nonce": "619", + "balance": "101110120254850000003", + "esdt": { + "str:CAN-14dc0a": "1000", + "str:CAN-2abf4b": "1000", + "str:CAN-6d39e6": "1000", + "str:CAN-ac1592": "1000" + }, + "username": "" + } + } + }, + { + "step": "setState", + "accounts": { + "0xb2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba": { + "nonce": "251", + "balance": "101558004165010000000", + "esdt": { + "str:CAMP-3bd1c7": { + "instances": [ + { + "nonce": "26", + "balance": "1" + }, + { + "nonce": "23", + "balance": "1" + }, + { + "nonce": "21", + "balance": "1" + }, + { + "nonce": "25", + "balance": "1" + }, + { + "nonce": "24", + "balance": "1" + }, + { + "nonce": "22", + "balance": "1" + } + ] + }, + "str:TEST-0f54a2": { + "instances": [ + { + "nonce": "9", + "balance": "1" + }, + { + "nonce": "1", + "balance": "1" + }, + { + "nonce": "2", + "balance": "1" + }, + { + "nonce": "6", + "balance": "1" + } + ] + }, + "str:TEST-48ef66": { + "instances": [ + { + "nonce": "5", + "balance": "1" + }, + { + "nonce": "4", + "balance": "1" + } + ] + }, + "str:TEST-d2b50f": { + "instances": [ + { + "nonce": "1", + "balance": "2" + } + ] + }, + "str:TEST-fb415a": { + "instances": [ + { + "nonce": "3", + "balance": "1" + }, + { + "nonce": "2", + "balance": "1" + }, + { + "nonce": "4", + "balance": "1" + } + ] + } + }, + "username": "" + } + } + }, + { + "step": "setState", + "accounts": { + "0xb13a017423c366caff8cecfb77a12610a130f4888134122c7937feae0d6d7d17": { + "nonce": "222", + "balance": "1767500200900000000", + "username": "" + } + } + }, + { + "step": "setState", + "accounts": { + "0x3af8d9c9423b2577c6252722c1d90212a4111f7203f9744f76fcfa1d0a310033": { + "nonce": "434", + "balance": "62227641093810000000", + "esdt": { + "str:USDC-091bd3": "9997000000000", + "str:XRF-079f0d": "999999805000000000000000000", + "str:XUSDC-929b9b": "1000000000000000000000000" + }, + "username": "" + } + } + }, + { + "step": "setState", + "accounts": { + "0x00000000000000000500c114ee7698050a4d40c092add8c31d25e99a6e1ec2ee": { + "nonce": "0", + "balance": "175064792195269569513", + "esdt": { + "str:WEGLD-6cf38e": { + "instances": [], + "roles": [ + "ESDTRoleLocalBurn", + "ESDTRoleLocalMint" + ] + } + }, + "username": "", + "storage": { + "0x7772617070656445676c64546f6b656e4964": "0x5745474c442d366366333865" + }, + "code": "0x0061736d0100000001661160000060017f0060027f7f017f60027f7f006000017f60017f017f60037f7f7f0060037f7f7f017f60057f7f7e7f7f017f60047f7f7f7f0060067e7f7f7f7f7f017f60047f7f7f7f017f60027f7e0060017e006000017e60057f7f7f7f7f0060037e7f7f0002cc062303656e760b7369676e616c4572726f72000303656e7618626967496e7447657445787465726e616c42616c616e6365000303656e760a6d4275666665724e6577000403656e760d6d427566666572417070656e64000203656e76096d4275666665724571000203656e76106d616e61676564534341646472657373000103656e761b6d616e61676564457865637574654f6e44657374436f6e74657874000a03656e760f636c65616e52657475726e44617461000003656e760d6d616e6167656443616c6c6572000103656e76136d616e616765644f776e657241646472657373000103656e76126d427566666572476574417267756d656e74000203656e760f6765744e756d417267756d656e7473000403656e76126d427566666572417070656e644279746573000703656e760f6d4275666665725365744279746573000703656e76106d4275666665724765744c656e677468000503656e76196d42756666657246726f6d426967496e74556e7369676e6564000203656e76136d42756666657247657442797465536c696365000b03656e76126d42756666657253746f726167654c6f6164000203656e76126d616e616765645369676e616c4572726f72000103656e760e626967496e74536574496e743634000c03656e760a626967496e745369676e000503656e76136d42756666657253746f7261676553746f7265000203656e760e636865636b4e6f5061796d656e74000003656e7614626967496e7446696e697368556e7369676e6564000103656e760d6d42756666657246696e697368000503656e7614736d616c6c496e7446696e6973685369676e6564000d03656e761c6d616e616765644765744d756c74694553445443616c6c56616c7565000103656e7609626967496e74436d70000203656e760a6765744761734c656674000e03656e761b6d616e616765645472616e7366657256616c756545786563757465000803656e76136765744e756d455344545472616e7366657273000403656e7612626967496e7447657443616c6c56616c7565000103656e7609626967496e74416464000603656e76226d616e616765644d756c74695472616e73666572455344544e465445786563757465000803656e760f6d42756666657247657442797465730002032c2b0f00040405020310010400010303040503020301050509030306060900040501000000000000000000000005030100110619037f01418080c0000b7f0041e5d1c0000b7f0041f0d1c0000b079b010c066d656d6f7279020004696e69740044146765744c6f636b656445676c6442616c616e63650045156765745772617070656445676c64546f6b656e496400460869735061757365640047057061757365004807756e706175736500490a756e7772617045676c64004a087772617045676c64004b0863616c6c4261636b004c0a5f5f646174615f656e6403010b5f5f686561705f6261736503020abc162b2e000240200120024d0440200220044d0d011024000b1024000b2000200220016b3602042000200120036a3602000b05001043000b2301027f10262200100520001026210041c5d1c00010221a41c5d1c0002000100120000b1b01017f41a483c00041a483c00028020041016b220036020020000b0f01017f10022201200010031a20010b0b0020002001100441004a0b0900200020011000000b1f01017f4167100510262203102b20004167200320012002102610061a10070b08002000420010130b0c01017f10262200100820000b1e01017f1026220010092000102c102804400f0b41f082c00041241000000b1500100b20004604400f0b41cb81c00041191000000b4701017f230041106b2202240020022001410874418080fc077120014118747220014108764180fe03712001411876727236020c20002002410c6a4104100c1a200241106a24000b0d0010311a200020011032102f0b1401017f1026220041d482c0004100100d1a20000b0f01017f102622012000100f1a20010b0d0010311a200020011027102f0b1101017f1026220220002001100d1a20020b09002000200110031a0b5501017f20002d00042101200041003a000402402001410171044041a883c00028020022014191ce004f0d01200028020041ac83c0002001100c1a41a883c000410036020041bcd1c00041003a00000b0f0b1024000bae0102027f017e230041106b2202240020024200370308200010382200100e220141094904402002200241086a41082001103920004100200228020422002002280200220110101a027f41002000450d001a034020000440200041016b210020013100002003420886842103200141016a21010c010b0b02402003420158044041002003a741016b0d021a0c010b41f281c0004112103a000b41010b200241106a24000f0b41e481c000410e103a000b0d0020001026220010111a20000b3b01017f230041106b22042400200441086a41002003200120021023200428020c21012000200428020836020020002001360204200441106a24000b1b01017f418482c00041161034220220002001100c1a20021012000bf20101047f230041106b2203240020032000100e22024118742002410874418080fc07717220024108764180fe03712002411876727236020c20012003410c6a4104103c20012d00042102200141003a00040240024002402002410171220204402000100e22054190ce0041a883c00028020022046b4b0d0220032004200420056a2204103d200041002003280204200328020010101a41a883c00020043602000c010b2001280200200010350b200120023a00040c010b2001103620012802002000103520012d0004200120023a0004410171450d0041a883c000410036020041bcd1c00041003a00000b200341106a24000b800101027f230041106b220324000240024020002d000404404190ce0041a883c00028020022046b2002490d01200341086a2004200220046a2200103d2003280208200328020c20012002103e41a883c00020003602000c020b200028020020012002100c1a0c010b20001036200028020020012002100c1a0b200341106a24000b4001017f230041106b22032400200341086a2001200241ac83c0004190ce001023200328020c21012000200328020836020020002001360204200341106a24000bb00201067f2001200346044020012203410f4b04402000410020006b41037122056a210420050440200221010340200020012d00003a0000200141016a2101200041016a22002004490d000b0b2004200320056b2203417c7122066a21000240200220056a220541037122010440200641004c0d012005417c71220741046a21024100200141037422086b4118712109200728020021010340200420012008762002280200220120097472360200200241046a2102200441046a22042000490d000b0c010b200641004c0d0020052102034020042002280200360200200241046a2102200441046a22042000490d000b0b20034103712103200520066a21020b20030440200020036a21010340200020022d00003a0000200241016a2102200041016a22002001490d000b0b0f0b1043000b1c0041be82c0004113103410374504400f0b419a82c00041121029000b0b0041ac82c000411210340b09002000101441004a0ba60101037f230041106b2201240041be82c00041131034200142808080808080808001420020001b3703080240200045044041d482c00021000c010b4100210003400240024020004108470440200141086a20006a2d00002202450d022002411874411f7520006a220041094f0d01410820006b21022000200141086a6a21000c040b1043000b104d000b200041016a21000c000b000b20002002103410151a200141106a24000b0500104d000b1a01017f10164101102e410010262200100a1a1040200010151a0b0c0010164100102e102510170b0f0010164100102e1040103810181a0b160010164100102e41be82c000411310341037ad10190b0e001016102d4100102e410110420b0e001016102d4100102e410010420bed0302097f017e230041106b220124004100102e103f416b2102024041c4d1c0002d000022000440416b41ffffffff0720001b21020c010b41c4d1c00041013a0000416b101a0b02402002100e4170714110460440410021002002100e2106200141086a2107410121050340200041106a220420064b0d022007420037030020014200370300200220004110200110101a2005044020012902042209423886200942288642808080808080c0ff0083842009421886428080808080e03f8320094208864280808080f01f838484200942088842808080f80f832009421888428080fc07838420094228884280fe038320094238888484842109200128020022004118742000410874418080fc07717220004108764180fe0371200041187672722108200128020c22004118742000410874418080fc07717220004108764180fe037120004118767272210341002105200421000c010b0b1043000b418481c00041221000000b024002400240200950044020081040103822041028450d0120031041450d0220031025101b41004a0d031031220020041033200020031030101c41ea80c000410d10342000102a102c2003420010311031101d1a200141106a24000f0b41d482c000411c1000000b418080c00041101029000b419080c000411c1029000b41ac80c00041231029000beb0301097f230041206b220124000240101e4504404100102e103f41752103024041c0d1c0002d000022000440417541ffffffff0720001b21030c010b41c0d1c00041013a00004175101f0b20031041450d011040103821041031220020041033200020031030101c41f780c000410d10342000102a102c10312107103121081031210520041027210210262200102b20002000200310202001420037020c20012002410874418080fc077120024118747220024108764180fe03712002411876727236020820012000410874418080fc077120004118747220004108764180fe0371200041187672723602142005200141086a4110100c1a200542002007200810211a2001027f41bcd1c0002d0000220045044041bcd1c00041013a000041a883c0004100360200200141ac83c0004190ce00410010392001280200200128020441d482c0004100103e10310c010b41d482c000410010340b360218200120004101733a001c2004200141186a2200103b200142003703082000200141086a22024108103c200310322000103b20012802182100200120012d001c3a000c2001200036020820021036200128020820012d000c044041a883c000410036020041bcd1c00041003a00000b10181a200141206a24000f0b41a681c00041251000000b41cf80c000411b1029000b0300010b0c00419483c000410e1000000b0bb8030200418080c0000ba20357726f6e67206573647420746f6b656e4d75737420706179206d6f7265207468616e203020746f6b656e7321436f6e747261637420646f6573206e6f74206861766520656e6f7567682066756e64735061796d656e74206d757374206265206d6f7265207468616e2030455344544c6f63616c4275726e455344544c6f63616c4d696e74696e636f7272656374206e756d626572206f662045534454207472616e736665727366756e6374696f6e20646f6573206e6f74206163636570742045534454207061796d656e7477726f6e67206e756d626572206f6620617267756d656e7473696e70757420746f6f206c6f6e67696e707574206f7574206f662072616e676573746f72616765206465636f6465206572726f723a20436f6e7472616374206973207061757365647772617070656445676c64546f6b656e496470617573655f6d6f64756c653a70617573656400000066756e6769626c65204553445420746f6b656e206578706563746564456e64706f696e742063616e206f6e6c792062652063616c6c6564206279206f776e657270616e6963206f636375727265640041a483c0000b049cffffff" + } + } + }, + { + "step": "setState", + "newAddresses": [ + { + "creatorAddress": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "creatorNonce": "619", + "newAddress": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60" + } + ] + }, + { + "step": "scDeploy", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "contractCode": "file:../output/multisig.wasm", + "arguments": [ + "0x02", + "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "0xb2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba", + "0xb13a017423c366caff8cecfb77a12610a130f4888134122c7937feae0d6d7d17", + "0x3af8d9c9423b2577c6252722c1d90212a4111f7203f9744f76fcfa1d0a310033" + ], + "gasLimit": "70,000,000", + "gasPrice": "" + }, + "expect": { + "status": "0" + } + }, + { + "step": "transfer", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "egldValue": "0,050000000000000000", + "gasLimit": "50,000" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "proposeAsyncCall", + "arguments": [ + "0x000000000000000000010000000000000000000000000000000000000002ffff", + "0xb1a2bc2ec50000", + "0x7265676973746572416e64536574416c6c526f6c6573", + "0x54657374436f6c6c656374696f6e31", + "0x54455354434f4c4c31", + "0x4e4654", + "0x" + ], + "gasLimit": "10,000,000", + "gasPrice": "" + }, + "expect": { + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xb2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x01" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xb13a017423c366caff8cecfb77a12610a130f4888134122c7937feae0d6d7d17", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x01" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0x3af8d9c9423b2577c6252722c1d90212a4111f7203f9744f76fcfa1d0a310033", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x01" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "setState", + "newTokenIdentifiers": [ + "TESTCOLL1-636884" + ] + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "performAction", + "arguments": [ + "0x01" + ], + "gasLimit": "80,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "proposeAsyncCall", + "arguments": [ + "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "0x", + "0x455344544e4654437265617465", + "0x54455354434f4c4c312d363336383834", + "0x01", + "0x5465737420636f6c6c656374696f6e206974656d202330", + "0x0bb8", + "0x", + "0x746167733a746573742c727573742d696e7465726163746f72", + "0x68747470733a2f2f697066732e696f2f697066732f516d5979416145663170684a53356d4e3677666f7535646535476270556464427854593156656b4b636a643550432f6e667430302e706e67" + ], + "gasLimit": "10,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "proposeAsyncCall", + "arguments": [ + "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "0x", + "0x455344544e4654437265617465", + "0x54455354434f4c4c312d363336383834", + "0x01", + "0x5465737420636f6c6c656374696f6e206974656d202331", + "0x0bb8", + "0x", + "0x746167733a746573742c727573742d696e7465726163746f72", + "0x68747470733a2f2f697066732e696f2f697066732f516d5979416145663170684a53356d4e3677666f7535646535476270556464427854593156656b4b636a643550432f6e667430312e706e67" + ], + "gasLimit": "10,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "proposeAsyncCall", + "arguments": [ + "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "0x", + "0x455344544e4654437265617465", + "0x54455354434f4c4c312d363336383834", + "0x01", + "0x5465737420636f6c6c656374696f6e206974656d202332", + "0x0bb8", + "0x", + "0x746167733a746573742c727573742d696e7465726163746f72", + "0x68747470733a2f2f697066732e696f2f697066732f516d5979416145663170684a53356d4e3677666f7535646535476270556464427854593156656b4b636a643550432f6e667430322e706e67" + ], + "gasLimit": "10,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xb2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x02" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xb13a017423c366caff8cecfb77a12610a130f4888134122c7937feae0d6d7d17", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x02" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0x3af8d9c9423b2577c6252722c1d90212a4111f7203f9744f76fcfa1d0a310033", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x02" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xb2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x03" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xb13a017423c366caff8cecfb77a12610a130f4888134122c7937feae0d6d7d17", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x03" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0x3af8d9c9423b2577c6252722c1d90212a4111f7203f9744f76fcfa1d0a310033", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x03" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xb2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x04" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xb13a017423c366caff8cecfb77a12610a130f4888134122c7937feae0d6d7d17", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x04" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0x3af8d9c9423b2577c6252722c1d90212a4111f7203f9744f76fcfa1d0a310033", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "sign", + "arguments": [ + "0x04" + ], + "gasLimit": "15,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "performAction", + "arguments": [ + "0x02" + ], + "gasLimit": "30,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "performAction", + "arguments": [ + "0x03" + ], + "gasLimit": "30,000,000", + "gasPrice": "" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "0xe32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed60", + "to": "0x000000000000000005008a3621a73196c9a9539f05be7d3c277346cdc989ed60", + "function": "performAction", + "arguments": [ + "0x04" + ], + "gasLimit": "30,000,000", + "gasPrice": "" + } + } + ] +} \ No newline at end of file diff --git a/contracts/examples/multisig/tests/multisig_scenario_go_test.rs b/contracts/examples/multisig/tests/multisig_scenario_go_test.rs index 3983c7a619..22c7328e6c 100644 --- a/contracts/examples/multisig/tests/multisig_scenario_go_test.rs +++ b/contracts/examples/multisig/tests/multisig_scenario_go_test.rs @@ -6,83 +6,88 @@ fn world() -> ScenarioWorld { #[test] fn call_other_shard_1_go() { - world().run("scenarios/call_other_shard-1.scen.json"); + multiversx_sc_scenario::run_go("scenarios/call_other_shard-1.scen.json"); } #[test] fn call_other_shard_2_go() { - world().run("scenarios/call_other_shard-2.scen.json"); + multiversx_sc_scenario::run_go("scenarios/call_other_shard-2.scen.json"); } #[test] fn change_board_go() { - world().run("scenarios/changeBoard.scen.json"); + multiversx_sc_scenario::run_go("scenarios/changeBoard.scen.json"); } #[test] fn change_quorum_go() { - world().run("scenarios/changeQuorum.scen.json"); + multiversx_sc_scenario::run_go("scenarios/changeQuorum.scen.json"); } #[test] fn change_quorum_too_big_go() { - world().run("scenarios/changeQuorum_tooBig.scen.json"); + multiversx_sc_scenario::run_go("scenarios/changeQuorum_tooBig.scen.json"); } #[test] fn deploy_adder_err_go() { - world().run("scenarios/deployAdder_err.scen.json"); + multiversx_sc_scenario::run_go("scenarios/deployAdder_err.scen.json"); } #[test] fn deploy_adder_then_call_go() { - world().run("scenarios/deployAdder_then_call.scen.json"); + multiversx_sc_scenario::run_go("scenarios/deployAdder_then_call.scen.json"); } #[test] fn deploy_factorial_go() { - world().run("scenarios/deployFactorial.scen.json"); + multiversx_sc_scenario::run_go("scenarios/deployFactorial.scen.json"); } #[test] fn deploy_other_multisig_go() { - world().run("scenarios/deployOtherMultisig.scen.json"); + multiversx_sc_scenario::run_go("scenarios/deployOtherMultisig.scen.json"); } #[test] fn deploy_duplicate_bm_go() { - world().run("scenarios/deploy_duplicate_bm.scen.json"); + multiversx_sc_scenario::run_go("scenarios/deploy_duplicate_bm.scen.json"); } #[test] #[ignore = "system SC not yet implemented"] fn interactor_nft_go() { - world().run("scenarios/interactor_nft.scen.json"); + multiversx_sc_scenario::run_go("scenarios/interactor_nft.scen.json"); +} + +#[test] +fn interactor_nft_all_roles_go() { + multiversx_sc_scenario::run_go("scenarios/interactor_nft_all_roles.scen.json"); } #[test] fn interactor_wegld_go() { - world().run("scenarios/interactor_wegld.scen.json"); + multiversx_sc_scenario::run_go("scenarios/interactor_wegld.scen.json"); } #[test] fn remove_everyone_go() { - world().run("scenarios/remove_everyone.scen.json"); + multiversx_sc_scenario::run_go("scenarios/remove_everyone.scen.json"); } // TODO: investigate gas issue #[test] #[ignore] fn send_esdt_go() { - world().run("scenarios/sendEsdt.scen.json"); + multiversx_sc_scenario::run_go("scenarios/sendEsdt.scen.json"); } #[test] fn upgrade_go() { - world().run("scenarios/upgrade.scen.json"); + multiversx_sc_scenario::run_go("scenarios/upgrade.scen.json"); } #[test] fn upgrade_from_source_go() { - world().run("scenarios/upgrade_from_source.scen.json"); + multiversx_sc_scenario::run_go("scenarios/upgrade_from_source.scen.json"); } diff --git a/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs b/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs index 3124ac2e89..c6dc14c495 100644 --- a/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs +++ b/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs @@ -32,81 +32,86 @@ fn world() -> ScenarioWorld { #[test] #[ignore] fn call_other_shard_1_rs() { - world().run("scenarios/call_other_shard-1.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/call_other_shard-1.scen.json", world()); } #[test] #[ignore] fn call_other_shard_2_rs() { - world().run("scenarios/call_other_shard-2.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/call_other_shard-2.scen.json", world()); } #[test] fn change_board_rs() { - world().run("scenarios/changeBoard.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/changeBoard.scen.json", world()); } #[test] fn change_quorum_rs() { - world().run("scenarios/changeQuorum.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/changeQuorum.scen.json", world()); } #[test] fn change_quorum_too_big_rs() { - world().run("scenarios/changeQuorum_tooBig.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/changeQuorum_tooBig.scen.json", world()); } #[test] fn deploy_adder_err_rs() { - world().run("scenarios/deployAdder_err.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/deployAdder_err.scen.json", world()); } #[test] fn deploy_adder_then_call_rs() { - world().run("scenarios/deployAdder_then_call.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/deployAdder_then_call.scen.json", world()); } #[test] fn deploy_factorial_rs() { - world().run("scenarios/deployFactorial.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/deployFactorial.scen.json", world()); } #[test] fn deploy_other_multisig_rs() { - world().run("scenarios/deployOtherMultisig.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/deployOtherMultisig.scen.json", world()); } #[test] fn deploy_duplicate_bm_rs() { - world().run("scenarios/deploy_duplicate_bm.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/deploy_duplicate_bm.scen.json", world()); } #[test] fn interactor_nft_rs() { - world().run("scenarios/interactor_nft.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/interactor_nft.scen.json", world()); +} + +#[test] +fn interactor_nft_all_roles_rs() { + multiversx_sc_scenario::run_rs("scenarios/interactor_nft_all_roles.scen.json", world()); } #[test] fn interactor_wegld_rs() { - world().run("scenarios/interactor_wegld.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/interactor_wegld.scen.json", world()); } #[test] fn remove_everyone_rs() { - world().run("scenarios/remove_everyone.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/remove_everyone.scen.json", world()); } #[test] fn send_esdt_rs() { - world().run("scenarios/sendEsdt.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/sendEsdt.scen.json", world()); } #[test] fn upgrade_rs() { - world().run("scenarios/upgrade.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/upgrade.scen.json", world()); } #[test] fn upgrade_from_source_rs() { - world().run("scenarios/upgrade_from_source.scen.json"); + multiversx_sc_scenario::run_rs("scenarios/upgrade_from_source.scen.json", world()); } From 3671cd3213f9e177a7240bcf38e4fe8a8c808390 Mon Sep 17 00:00:00 2001 From: Ovidiu Stinga Date: Wed, 5 Jul 2023 13:18:59 +0300 Subject: [PATCH 2/3] test-gen with new version --- .../tests/multisig_scenario_go_test.rs | 35 ++++++++++--------- .../tests/multisig_scenario_rs_test.rs | 35 ++++++++++--------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/contracts/examples/multisig/tests/multisig_scenario_go_test.rs b/contracts/examples/multisig/tests/multisig_scenario_go_test.rs index 22c7328e6c..6e7fc7464e 100644 --- a/contracts/examples/multisig/tests/multisig_scenario_go_test.rs +++ b/contracts/examples/multisig/tests/multisig_scenario_go_test.rs @@ -6,88 +6,89 @@ fn world() -> ScenarioWorld { #[test] fn call_other_shard_1_go() { - multiversx_sc_scenario::run_go("scenarios/call_other_shard-1.scen.json"); + world().run("scenarios/call_other_shard-1.scen.json"); } #[test] fn call_other_shard_2_go() { - multiversx_sc_scenario::run_go("scenarios/call_other_shard-2.scen.json"); + world().run("scenarios/call_other_shard-2.scen.json"); } #[test] fn change_board_go() { - multiversx_sc_scenario::run_go("scenarios/changeBoard.scen.json"); + world().run("scenarios/changeBoard.scen.json"); } #[test] fn change_quorum_go() { - multiversx_sc_scenario::run_go("scenarios/changeQuorum.scen.json"); + world().run("scenarios/changeQuorum.scen.json"); } #[test] fn change_quorum_too_big_go() { - multiversx_sc_scenario::run_go("scenarios/changeQuorum_tooBig.scen.json"); + world().run("scenarios/changeQuorum_tooBig.scen.json"); } #[test] fn deploy_adder_err_go() { - multiversx_sc_scenario::run_go("scenarios/deployAdder_err.scen.json"); + world().run("scenarios/deployAdder_err.scen.json"); } #[test] fn deploy_adder_then_call_go() { - multiversx_sc_scenario::run_go("scenarios/deployAdder_then_call.scen.json"); + world().run("scenarios/deployAdder_then_call.scen.json"); } #[test] fn deploy_factorial_go() { - multiversx_sc_scenario::run_go("scenarios/deployFactorial.scen.json"); + world().run("scenarios/deployFactorial.scen.json"); } #[test] fn deploy_other_multisig_go() { - multiversx_sc_scenario::run_go("scenarios/deployOtherMultisig.scen.json"); + world().run("scenarios/deployOtherMultisig.scen.json"); } #[test] fn deploy_duplicate_bm_go() { - multiversx_sc_scenario::run_go("scenarios/deploy_duplicate_bm.scen.json"); + world().run("scenarios/deploy_duplicate_bm.scen.json"); } #[test] #[ignore = "system SC not yet implemented"] fn interactor_nft_go() { - multiversx_sc_scenario::run_go("scenarios/interactor_nft.scen.json"); + world().run("scenarios/interactor_nft.scen.json"); } #[test] +#[ignore = "system SC not yet implemented"] fn interactor_nft_all_roles_go() { - multiversx_sc_scenario::run_go("scenarios/interactor_nft_all_roles.scen.json"); + world().run("scenarios/interactor_nft_all_roles.scen.json"); } #[test] fn interactor_wegld_go() { - multiversx_sc_scenario::run_go("scenarios/interactor_wegld.scen.json"); + world().run("scenarios/interactor_wegld.scen.json"); } #[test] fn remove_everyone_go() { - multiversx_sc_scenario::run_go("scenarios/remove_everyone.scen.json"); + world().run("scenarios/remove_everyone.scen.json"); } // TODO: investigate gas issue #[test] #[ignore] fn send_esdt_go() { - multiversx_sc_scenario::run_go("scenarios/sendEsdt.scen.json"); + world().run("scenarios/sendEsdt.scen.json"); } #[test] fn upgrade_go() { - multiversx_sc_scenario::run_go("scenarios/upgrade.scen.json"); + world().run("scenarios/upgrade.scen.json"); } #[test] fn upgrade_from_source_go() { - multiversx_sc_scenario::run_go("scenarios/upgrade_from_source.scen.json"); + world().run("scenarios/upgrade_from_source.scen.json"); } diff --git a/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs b/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs index c6dc14c495..3220babdc1 100644 --- a/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs +++ b/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs @@ -32,86 +32,87 @@ fn world() -> ScenarioWorld { #[test] #[ignore] fn call_other_shard_1_rs() { - multiversx_sc_scenario::run_rs("scenarios/call_other_shard-1.scen.json", world()); + world().run("scenarios/call_other_shard-1.scen.json"); } #[test] #[ignore] fn call_other_shard_2_rs() { - multiversx_sc_scenario::run_rs("scenarios/call_other_shard-2.scen.json", world()); + world().run("scenarios/call_other_shard-2.scen.json"); } #[test] fn change_board_rs() { - multiversx_sc_scenario::run_rs("scenarios/changeBoard.scen.json", world()); + world().run("scenarios/changeBoard.scen.json"); } #[test] fn change_quorum_rs() { - multiversx_sc_scenario::run_rs("scenarios/changeQuorum.scen.json", world()); + world().run("scenarios/changeQuorum.scen.json"); } #[test] fn change_quorum_too_big_rs() { - multiversx_sc_scenario::run_rs("scenarios/changeQuorum_tooBig.scen.json", world()); + world().run("scenarios/changeQuorum_tooBig.scen.json"); } #[test] fn deploy_adder_err_rs() { - multiversx_sc_scenario::run_rs("scenarios/deployAdder_err.scen.json", world()); + world().run("scenarios/deployAdder_err.scen.json"); } #[test] fn deploy_adder_then_call_rs() { - multiversx_sc_scenario::run_rs("scenarios/deployAdder_then_call.scen.json", world()); + world().run("scenarios/deployAdder_then_call.scen.json"); } #[test] fn deploy_factorial_rs() { - multiversx_sc_scenario::run_rs("scenarios/deployFactorial.scen.json", world()); + world().run("scenarios/deployFactorial.scen.json"); } #[test] fn deploy_other_multisig_rs() { - multiversx_sc_scenario::run_rs("scenarios/deployOtherMultisig.scen.json", world()); + world().run("scenarios/deployOtherMultisig.scen.json"); } #[test] fn deploy_duplicate_bm_rs() { - multiversx_sc_scenario::run_rs("scenarios/deploy_duplicate_bm.scen.json", world()); + world().run("scenarios/deploy_duplicate_bm.scen.json"); } #[test] fn interactor_nft_rs() { - multiversx_sc_scenario::run_rs("scenarios/interactor_nft.scen.json", world()); + world().run("scenarios/interactor_nft.scen.json"); } #[test] +#[should_panic(expected = "not implemented")] fn interactor_nft_all_roles_rs() { - multiversx_sc_scenario::run_rs("scenarios/interactor_nft_all_roles.scen.json", world()); + world().run("scenarios/interactor_nft_all_roles.scen.json"); } #[test] fn interactor_wegld_rs() { - multiversx_sc_scenario::run_rs("scenarios/interactor_wegld.scen.json", world()); + world().run("scenarios/interactor_wegld.scen.json"); } #[test] fn remove_everyone_rs() { - multiversx_sc_scenario::run_rs("scenarios/remove_everyone.scen.json", world()); + world().run("scenarios/remove_everyone.scen.json"); } #[test] fn send_esdt_rs() { - multiversx_sc_scenario::run_rs("scenarios/sendEsdt.scen.json", world()); + world().run("scenarios/sendEsdt.scen.json"); } #[test] fn upgrade_rs() { - multiversx_sc_scenario::run_rs("scenarios/upgrade.scen.json", world()); + world().run("scenarios/upgrade.scen.json"); } #[test] fn upgrade_from_source_rs() { - multiversx_sc_scenario::run_rs("scenarios/upgrade_from_source.scen.json", world()); + world().run("scenarios/upgrade_from_source.scen.json"); } From 1b786f7b51059433a799063f09165b7e8cb97ca1 Mon Sep 17 00:00:00 2001 From: Ovidiu Stinga Date: Wed, 5 Jul 2023 18:39:27 +0300 Subject: [PATCH 3/3] system_mock register and set all roles and refactor --- .../tests/multisig_scenario_rs_test.rs | 1 - vm/src/tx_execution/system_sc.rs | 2 +- .../tx_execution/system_sc/system_sc_issue.rs | 86 +++++++++++-------- .../system_sc/system_sc_unimplemented.rs | 9 +- vm/src/world_mock/esdt_data.rs | 53 +++++++++--- 5 files changed, 93 insertions(+), 58 deletions(-) diff --git a/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs b/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs index 3220babdc1..27d286e1d9 100644 --- a/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs +++ b/contracts/examples/multisig/tests/multisig_scenario_rs_test.rs @@ -87,7 +87,6 @@ fn interactor_nft_rs() { } #[test] -#[should_panic(expected = "not implemented")] fn interactor_nft_all_roles_rs() { world().run("scenarios/interactor_nft_all_roles.scen.json"); } diff --git a/vm/src/tx_execution/system_sc.rs b/vm/src/tx_execution/system_sc.rs index b8e7a4b380..d3103e0239 100644 --- a/vm/src/tx_execution/system_sc.rs +++ b/vm/src/tx_execution/system_sc.rs @@ -28,7 +28,7 @@ pub fn execute_system_sc(tx_context: TxContext) -> (TxContext, TxResult) { "issueNonFungible" => issue_non_fungible(tx_context), "registerMetaESDT" => register_meta_esdt(tx_context), "changeSFTToMetaESDT" => change_sft_to_meta_esdt(tx_context), - "registerAndSetAllRoles" => register_and_set_all_roles(), + "registerAndSetAllRoles" => register_and_set_all_roles(tx_context), "ESDTBurn" => esdt_burn(tx_context), "mint" => mint(tx_context), "freeze" => freeze(tx_context), diff --git a/vm/src/tx_execution/system_sc/system_sc_issue.rs b/vm/src/tx_execution/system_sc/system_sc_issue.rs index cb9c0fcea9..00f946e67e 100644 --- a/vm/src/tx_execution/system_sc/system_sc_issue.rs +++ b/vm/src/tx_execution/system_sc/system_sc_issue.rs @@ -6,7 +6,8 @@ use crate::{ types::top_decode_u64, }; -/// Issues a new token. +/// Issues a new fungible token. +#[allow(unused_variables)] pub fn issue(tx_context: TxContext) -> (TxContext, TxResult) { let tx_input = tx_context.input_ref(); let tx_cache = tx_context.blockchain_cache(); @@ -16,46 +17,33 @@ pub fn issue(tx_context: TxContext) -> (TxContext, TxResult) { tx_result = TxResult::from_vm_error("not enough arguments"); return (tx_context, tx_result); } - let _name = tx_input.args[0].clone(); + let name = tx_input.args[0].clone(); let ticker = tx_input.args[1].clone(); - let _total_supply = BigUint::from_bytes_be(tx_input.args[2].clone().as_ref()); - let _decimals = top_decode_u64(tx_input.args[3].clone().as_ref()) as u32; + let total_supply = BigUint::from_bytes_be(tx_input.args[2].clone().as_ref()); + let decimals = top_decode_u64(tx_input.args[3].clone().as_ref()) as u32; - let mut new_token_identifiers = tx_cache.get_new_token_identifiers(); - - let token_identifier = if let Some((i, ti)) = - first_token_identifier_with_ticker(&new_token_identifiers, &ticker) - { - new_token_identifiers.remove(i); - ti.into_bytes() - } else { - generate_token_identifier_from_ticker(tx_input, tx_cache, &ticker) - }; - - println!( - "\n\ngenerated new token_identifier: {}\n\n", - std::str::from_utf8(&token_identifier).unwrap() - ); - - tx_cache.with_account_mut(&tx_input.from, |account| { - account.esdt.issue_token(&token_identifier); - }); - tx_cache.set_new_token_identifiers(new_token_identifiers); - - tx_result = TxResult { - result_values: vec![token_identifier], - ..Default::default() - }; - - (tx_context, tx_result) + register_and_set_roles(tx_context, ticker, "FT".to_string()) } /// Issues a new semi-fungible token. +#[allow(unused_variables)] pub fn issue_semi_fungible(tx_context: TxContext) -> (TxContext, TxResult) { - issue_non_fungible(tx_context) + let tx_input = tx_context.input_ref(); + let tx_cache = tx_context.blockchain_cache(); + let tx_result: TxResult; + + if tx_input.args.len() < 2 { + tx_result = TxResult::from_vm_error("not enough arguments"); + return (tx_context, tx_result); + } + let name = tx_input.args[0].clone(); + let ticker = tx_input.args[1].clone(); + + register_and_set_roles(tx_context, ticker, "SFT".to_string()) } /// Issues a new non-fungible token. +#[allow(unused_variables)] pub fn issue_non_fungible(tx_context: TxContext) -> (TxContext, TxResult) { let tx_input = tx_context.input_ref(); let tx_cache = tx_context.blockchain_cache(); @@ -65,9 +53,35 @@ pub fn issue_non_fungible(tx_context: TxContext) -> (TxContext, TxResult) { tx_result = TxResult::from_vm_error("not enough arguments"); return (tx_context, tx_result); } - let _name = tx_input.args[0].clone(); + let name = tx_input.args[0].clone(); let ticker = tx_input.args[1].clone(); + register_and_set_roles(tx_context, ticker, "NFT".to_string()) +} + +// Issues a new token and sets all roles for its type. +#[allow(unused_variables)] +pub fn register_and_set_all_roles(tx_context: TxContext) -> (TxContext, TxResult) { + let tx_input = tx_context.input_ref(); + let tx_cache = tx_context.blockchain_cache(); + + if tx_input.args.len() < 4 { + let tx_result = TxResult::from_vm_error("not enough arguments"); + return (tx_context, tx_result); + } + + let name = tx_input.args[0].clone(); + let ticker = tx_input.args[1].clone(); + let token_type = String::from_utf8(tx_input.args[2].clone()).unwrap(); + let decimals = top_decode_u64(tx_input.args[3].clone().as_ref()) as u32; + + register_and_set_roles(tx_context, ticker, token_type) +} + +fn register_and_set_roles(tx_context: TxContext, ticker: Vec, token_type: String) -> (TxContext, TxResult) { + let tx_input = tx_context.input_ref(); + let tx_cache = tx_context.blockchain_cache(); + let mut new_token_identifiers = tx_cache.get_new_token_identifiers(); let token_identifier = if let Some((i, ti)) = @@ -80,11 +94,13 @@ pub fn issue_non_fungible(tx_context: TxContext) -> (TxContext, TxResult) { }; tx_cache.with_account_mut(&tx_input.from, |account| { - account.esdt.issue_token(&token_identifier); + account + .esdt + .register_and_set_roles(&token_identifier, &token_type); }); tx_cache.set_new_token_identifiers(new_token_identifiers); - tx_result = TxResult { + let tx_result = TxResult { result_values: vec![token_identifier], ..Default::default() }; diff --git a/vm/src/tx_execution/system_sc/system_sc_unimplemented.rs b/vm/src/tx_execution/system_sc/system_sc_unimplemented.rs index 9d4d07ce96..3a25157294 100644 --- a/vm/src/tx_execution/system_sc/system_sc_unimplemented.rs +++ b/vm/src/tx_execution/system_sc/system_sc_unimplemented.rs @@ -9,17 +9,12 @@ pub fn register_meta_esdt(tx_context: TxContext) -> (TxContext, TxResult) { } #[allow(unused_variables)] -pub fn change_sft_to_meta_esdt(_tx_context: TxContext) -> (TxContext, TxResult) { +pub fn change_sft_to_meta_esdt(tx_context: TxContext) -> (TxContext, TxResult) { unimplemented!() } #[allow(unused_variables)] -pub fn register_and_set_all_roles() -> (TxContext, TxResult) { - unimplemented!() -} - -#[allow(unused_variables)] -pub fn esdt_burn(_tx_context: TxContext) -> (TxContext, TxResult) { +pub fn esdt_burn(tx_context: TxContext) -> (TxContext, TxResult) { unimplemented!() } diff --git a/vm/src/world_mock/esdt_data.rs b/vm/src/world_mock/esdt_data.rs index d44098bb4f..6e44782af9 100644 --- a/vm/src/world_mock/esdt_data.rs +++ b/vm/src/world_mock/esdt_data.rs @@ -150,31 +150,56 @@ impl AccountEsdt { self.0.iter() } - pub fn issue_token(&mut self, token_identifier: &[u8]) { - let roles = vec![ - "ESDTLocalMint".as_bytes().to_vec(), - "ESDTLocalBurn".as_bytes().to_vec(), - ]; + pub fn set_special_role(&mut self, token_identifier: &[u8], role: &[u8]) { + if let Some(esdt_data) = self.get_mut_by_identifier(token_identifier) { + let roles = esdt_data.roles.get(); + if !roles.contains(role.to_vec().as_ref()) { + let mut new_roles = roles; + new_roles.push(role.to_vec()); + esdt_data.roles = EsdtRoles::new(new_roles); + } + } + } + + pub fn register_and_set_roles(&mut self, token_identifier: &[u8], token_type: &str) { + self.issue_token(token_identifier); + self.set_roles( + token_identifier.to_vec(), + Self::get_all_roles_for_token_type(token_type), + ); + } + fn issue_token(&mut self, token_identifier: &[u8]) { self.0.insert( token_identifier.to_vec(), EsdtData { instances: EsdtInstances::new(), last_nonce: 0, - roles: EsdtRoles::new(roles), + roles: EsdtRoles::default(), frozen: false, }, ); } - pub fn set_special_role(&mut self, token_identifier: &[u8], role: &[u8]) { - if let Some(esdt_data) = self.get_mut_by_identifier(token_identifier) { - let roles = esdt_data.roles.get(); - if !roles.contains(role.to_vec().as_ref()) { - let mut new_roles = roles; - new_roles.push(role.to_vec()); - esdt_data.roles = EsdtRoles::new(new_roles); - } + fn get_all_roles_for_token_type(token_type: &str) -> Vec> { + match token_type { + "NFT" => vec![ + "ESDTRoleNFTCreate".as_bytes().to_vec(), + "ESDTRoleNFTBurn".as_bytes().to_vec(), + "ESDTRoleNFTUpdateAttributes".as_bytes().to_vec(), + "ESDTRoleNFTAddURI".as_bytes().to_vec(), + ], + "SFT" | "META" => vec![ + "ESDTRoleNFTCreate".as_bytes().to_vec(), + "ESDTRoleNFTBurn".as_bytes().to_vec(), + "ESDTRoleNFTAddQuantity".as_bytes().to_vec(), + ], + "FNG" => vec![ + "ESDTRoleLocalMint".as_bytes().to_vec(), + "ESDTRoleLocalBurn".as_bytes().to_vec(), + "ESDTRoleLocalTransfer".as_bytes().to_vec(), + ], + _ => panic!("invalid token type"), } } }