Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MedovTimur authored Jul 24, 2024
1 parent e42759c commit 8faf0b6
Show file tree
Hide file tree
Showing 101 changed files with 1,996 additions and 1,975 deletions.
1,794 changes: 891 additions & 903 deletions contracts/Cargo.lock

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ members = [
"dao/state",
"dao-light",
"dao-light/state",
"ddns",
"ddns/state",
"decentralized-git",
"decentralized-git/master",
"decentralized-git/master/state",
Expand Down Expand Up @@ -161,7 +159,6 @@ concert-io.path = "concert/io"
crowdsale-io.path = "crowdsale/io"
dao-io.path = "dao/io"
dao-light-io.path = "dao-light/io"
ddns-io.path = "ddns/io"
decentralized-git-io.path = "decentralized-git/io"
decentralized-git-master-io.path = "decentralized-git/master/io"
decentralized-git-user-io.path = "decentralized-git/user/io"
Expand Down Expand Up @@ -228,13 +225,13 @@ gstd = "1.4.2"
gear-wasm-builder = "1.4.2"
gmeta = "1.4.2"
gclient = "1.4.2"
gtest = { git = "https://github.com/gear-tech/gear", tag = "v1.4.2" }
gtest = "1.4.2"
gear-core = "1.4.2"

# External

primitive-types = { version = "0.12", default-features = false }
sp-core = { version = "22", default-features = false, features = ["full_crypto", "sp-externalities"] }
sp-core = { version = "21.0.0", default-features = false, features = ["full_crypto", "sp-externalities"] }
sp-core-hashing = { version = "10", default-features = false }
tokio = "1"
blake2-rfc = "0.2"
Expand Down
144 changes: 73 additions & 71 deletions contracts/auto-changed-nft/tests/nft_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ZERO_ID: u64 = 0;
fn mint_success() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let transaction_id: u64 = 0;
let res = mint(&nft, transaction_id, USERS[0]);
let message = NFTEvent::Transfer(NFTTransfer {
Expand Down Expand Up @@ -50,7 +50,7 @@ fn mint_limit_exceed() {

assert!(!res.main_failed());

let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let transaction_id: u64 = 0;
let res = mint(&nft, transaction_id, USERS[0]);
assert!(!res.main_failed());
Expand Down Expand Up @@ -83,7 +83,7 @@ fn mint_authorized() {

assert!(!res.main_failed());

let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let transaction_id: u64 = 0;
let res = mint(&nft, transaction_id, USERS[0]);
assert!(!res.main_failed());
Expand Down Expand Up @@ -116,7 +116,7 @@ fn mint_not_authorized() {

assert!(!res.main_failed());

let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let transaction_id: u64 = 0;
let res = mint(&nft, transaction_id, USERS[0]);
assert!(!res.main_failed());
Expand Down Expand Up @@ -149,7 +149,7 @@ fn mint_added() {

assert!(!res.main_failed());

let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let transaction_id: u64 = 0;
let res = add_minter(&nft, transaction_id, USERS[1].into(), USERS[0]);
assert!(!res.main_failed());
Expand All @@ -164,7 +164,7 @@ fn mint_added() {
fn burn_success() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let mut transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());
transaction_id += 1;
Expand All @@ -182,7 +182,7 @@ fn burn_success() {
fn burn_failures() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let mut transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());
// must fail since the token doesn't exist
Expand All @@ -197,7 +197,7 @@ fn burn_failures() {
fn transfer_success() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let mut transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());
transaction_id += 1;
Expand All @@ -215,7 +215,7 @@ fn transfer_success() {
fn transfer_failures() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let mut transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());

Expand All @@ -234,7 +234,7 @@ fn transfer_failures() {
fn owner_success() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let mut transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());
transaction_id += 1;
Expand All @@ -253,7 +253,7 @@ fn owner_success() {
fn is_approved_to_success() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let mut transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());
transaction_id += 1;
Expand Down Expand Up @@ -284,7 +284,7 @@ fn is_approved_to_success() {
fn is_approved_to_failure() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let mut transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());
transaction_id += 1;
Expand All @@ -298,7 +298,7 @@ fn is_approved_to_failure() {
fn approve_success() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let mut transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());
transaction_id += 1;
Expand All @@ -314,66 +314,68 @@ fn approve_success() {
assert!(!transfer(&nft, transaction_id, USERS[1], USERS[2], 0).main_failed());
}

#[test]
fn auto_change_success() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());

let link1 = "link 1";
let link2 = "link 2";
let link3 = "link 3";
let link4 = "link 4";

let token_id = TokenId::default();
assert!(!add_url(&nft, token_id, link1, USERS[0]).main_failed());
assert!(!add_url(&nft, token_id, link2, USERS[0]).main_failed());
assert!(!add_url(&nft, token_id, link3, USERS[0]).main_failed());
assert!(!add_url(&nft, token_id, link4, USERS[0]).main_failed());

let updates_count = 8;
let updates_period = 5;
assert!(!start_auto_changing(
&nft,
vec![token_id],
updates_count,
updates_period,
USERS[0]
)
.main_failed());

// Start update
assert_eq!(current_media(&nft, token_id), link1);
sys.spend_blocks(updates_period);
assert_eq!(current_media(&nft, token_id), link4);

sys.spend_blocks(updates_period);
assert_eq!(current_media(&nft, token_id), link3);

sys.spend_blocks(updates_period);
assert_eq!(current_media(&nft, token_id), link2);

// Media rotation happens
sys.spend_blocks(updates_period);
assert_eq!(current_media(&nft, token_id), link1);

sys.spend_blocks(updates_period);
assert_eq!(current_media(&nft, token_id), link4);

sys.spend_blocks(updates_period);
assert_eq!(current_media(&nft, token_id), link3);

sys.spend_blocks(updates_period);
assert_eq!(current_media(&nft, token_id), link2);
}
// TODO: uncomment after fixing the gas tree

// #[test]
// fn auto_change_success() {
// let sys = System::new();
// init_nft(&sys);
// let nft = sys.get_program(1).unwrap();
// let transaction_id: u64 = 0;
// assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());

// let link1 = "link 1";
// let link2 = "link 2";
// let link3 = "link 3";
// let link4 = "link 4";

// let token_id = TokenId::default();
// assert!(!add_url(&nft, token_id, link1, USERS[0]).main_failed());
// assert!(!add_url(&nft, token_id, link2, USERS[0]).main_failed());
// assert!(!add_url(&nft, token_id, link3, USERS[0]).main_failed());
// assert!(!add_url(&nft, token_id, link4, USERS[0]).main_failed());

// let updates_count = 8;
// let updates_period = 5;
// assert!(!start_auto_changing(
// &nft,
// vec![token_id],
// updates_count,
// updates_period,
// USERS[0]
// )
// .main_failed());

// // Start update
// assert_eq!(current_media(&nft, token_id), link1);
// sys.spend_blocks(updates_period);
// assert_eq!(current_media(&nft, token_id), link4);

// sys.spend_blocks(updates_period);
// assert_eq!(current_media(&nft, token_id), link3);

// sys.spend_blocks(updates_period);
// assert_eq!(current_media(&nft, token_id), link2);

// // Media rotation happens
// sys.spend_blocks(updates_period);
// assert_eq!(current_media(&nft, token_id), link1);

// sys.spend_blocks(updates_period);
// assert_eq!(current_media(&nft, token_id), link4);

// sys.spend_blocks(updates_period);
// assert_eq!(current_media(&nft, token_id), link3);

// sys.spend_blocks(updates_period);
// assert_eq!(current_media(&nft, token_id), link2);
// }

#[test]
fn approve_failures() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let mut transaction_id: u64 = 0;
assert!(!mint(&nft, transaction_id, USERS[0]).main_failed());
transaction_id += 1;
Expand Down Expand Up @@ -401,7 +403,7 @@ fn approve_failures() {
fn delegated_approve_success() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let pair = Sr25519Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
Expand Down Expand Up @@ -436,7 +438,7 @@ fn delegated_approve_success() {
fn delegated_approve_failures() {
let sys = System::new();
init_nft(&sys);
let nft = sys.get_program(1);
let nft = sys.get_program(1).unwrap();
let pair = Sr25519Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
Expand Down Expand Up @@ -475,7 +477,7 @@ fn delegated_approve_failures() {
assert!(delegated_approve(&nft, transaction_id, USERS[0], message, signature.0).main_failed());
// Must fail if user tries to approve token in wrong contract
init_nft(&sys);
let second_nft = sys.get_program(2);
let second_nft = sys.get_program(2).unwrap();
transaction_id += 1;
assert!(!add_minter(&second_nft, transaction_id, owner_id.into(), USERS[0]).main_failed());
transaction_id += 1;
Expand Down
7 changes: 6 additions & 1 deletion contracts/auto-changed-nft/tests/node_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,12 @@ async fn gclient_auto_changed() -> Result<()> {
name: String::from("MyToken"),
description: String::from("My token"),
};
let actor_id = ActorId::from_slice(&api.account_id().encode()).unwrap();
let actor_id = ActorId::new(
api.account_id()
.encode()
.try_into()
.expect("Unexpected invalid account id length."),
);
let init_nft = InitNFT {
collection,
royalties: None,
Expand Down
1 change: 1 addition & 0 deletions contracts/auto-changed-nft/tests/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use auto_changed_nft_io::*;
use gear_lib_old::non_fungible_token::token::*;
use gstd::ActorId;
Expand Down
Loading

0 comments on commit 8faf0b6

Please sign in to comment.