From 0b4f476e8ad8d3d829f25bb2ac802b071c6824f1 Mon Sep 17 00:00:00 2001 From: Geoffrey Mureithi Date: Fri, 8 Dec 2023 13:55:06 +0300 Subject: [PATCH 1/2] bump: to version 20 --- .github/workflows/contracts.yml | 2 +- Cargo.toml | 2 +- contracts/governance/src/participant.rs | 6 +- contracts/governance/src/test.rs | 90 ++++++++++++------------- contracts/lottery/src/test.rs | 66 +++++++++--------- contracts/marketplace/src/test.rs | 16 ++--- contracts/payment_splitter/src/test.rs | 18 ++--- contracts/raffle/src/test.rs | 34 +++++----- contracts/shared/src/rand.rs | 2 +- contracts/simple_voting/src/test.rs | 10 +-- contracts/voting/src/test.rs | 40 +++++------ crates/nebula-importer/src/lib.rs | 4 +- 12 files changed, 145 insertions(+), 145 deletions(-) diff --git a/.github/workflows/contracts.yml b/.github/workflows/contracts.yml index fb6a80c9..ae5be736 100644 --- a/.github/workflows/contracts.yml +++ b/.github/workflows/contracts.yml @@ -82,7 +82,7 @@ jobs: uses: baptiste0928/cargo-install@v2 with: crate: soroban-cli - version: "^20.0.0-rc2" + version: "^20.0.0" - name: Download wasm-files uses: actions/download-artifact@v3 diff --git a/Cargo.toml b/Cargo.toml index 53c3c652..15fe9d13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,4 +49,4 @@ debug-assertions = true [workspace.dependencies.soroban-sdk] -version = "20.0.0-rc2" +version = "20.0.0" diff --git a/contracts/governance/src/participant.rs b/contracts/governance/src/participant.rs index 8cc51a1f..e9c4f50a 100644 --- a/contracts/governance/src/participant.rs +++ b/contracts/governance/src/participant.rs @@ -128,7 +128,7 @@ mod test { #[test] fn participant_can_only_increase_positive_amounts() { let env = Env::default(); - let mut p = Participant::new(Address::random(&env)); + let mut p = Participant::new(Address::generate(&env)); assert_eq!(Err(Error::InvalidAmount), p.increase_balance(0)); assert_eq!(Err(Error::InvalidAmount), p.increase_balance(-1)); p.increase_balance(1).unwrap(); @@ -137,7 +137,7 @@ mod test { #[test] fn participant_can_only_decrease_positive_amounts() { let env = Env::default(); - let mut p = Participant::new(Address::random(&env)); + let mut p = Participant::new(Address::generate(&env)); p.increase_balance(5).unwrap(); assert_eq!(Err(Error::InvalidAmount), p.decrease_balance(0)); @@ -148,7 +148,7 @@ mod test { #[test] fn participant_cannot_decrease_more_than_it_has() { let env = Env::default(); - let mut p = Participant::new(Address::random(&env)); + let mut p = Participant::new(Address::generate(&env)); p.increase_balance(1).unwrap(); assert_eq!(Err(Error::InsufficientFunds), p.decrease_balance(2)); } diff --git a/contracts/governance/src/test.rs b/contracts/governance/src/test.rs index c1b71020..ca06681a 100644 --- a/contracts/governance/src/test.rs +++ b/contracts/governance/src/test.rs @@ -19,7 +19,7 @@ fn cannot_be_initialized_twice() { sc.env.mock_all_auths(); sc.contract_client.init( - &Address::random(&sc.env), + &Address::generate(&sc.env), &sc.token_admin_client.address, &864000, &5000, @@ -30,15 +30,15 @@ fn cannot_be_initialized_twice() { fn setup_scenario<'a>() -> Scenario<'a> { let env = Env::default(); - let contract_id = env.register_contract(Some(&Address::random(&env)), GovernanceContract); + let contract_id = env.register_contract(Some(&Address::generate(&env)), GovernanceContract); let contract_client = GovernanceContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let token_addr = env.register_stellar_asset_contract(token_admin.clone()); let token_admin_client = token::StellarAssetClient::new(&env, &token_addr); let token_client = token::Client::new(&env, &token_addr); - let curator = Address::random(&env); + let curator = Address::generate(&env); contract_client.init( &curator.clone(), @@ -78,7 +78,7 @@ fn participant_can_join() { sc.env.mock_all_auths(); - let participant_addr = Address::random(&sc.env); + let participant_addr = Address::generate(&sc.env); // Add funds to client address (as participant) sc.token_admin_client.mint(&participant_addr, &1000); @@ -147,7 +147,7 @@ fn participant_cant_join_without_enough_funds() { let sc = setup_scenario(); sc.env.mock_all_auths(); - let participant_addr = Address::random(&sc.env); + let participant_addr = Address::generate(&sc.env); sc.token_admin_client.mint(&participant_addr, &199); sc.contract_client.join(&participant_addr, &200); @@ -160,7 +160,7 @@ fn participant_cant_join_with_negative_stake() { sc.env.mock_all_auths(); - let participant_addr = Address::random(&sc.env); + let participant_addr = Address::generate(&sc.env); sc.token_admin_client.mint(&participant_addr, &199); sc.contract_client.join(&participant_addr, &-1); @@ -173,7 +173,7 @@ fn participant_cant_join_with_zero_stake() { sc.env.mock_all_auths(); - let participant_addr = Address::random(&sc.env); + let participant_addr = Address::generate(&sc.env); sc.token_admin_client.mint(&participant_addr, &199); sc.contract_client.join(&participant_addr, &0); @@ -185,7 +185,7 @@ fn participant_can_leave_withdrawing_all_funds() { sc.env.mock_all_auths(); - let participant_addr = Address::random(&sc.env); + let participant_addr = Address::generate(&sc.env); // Add funds to client address (as participant) sc.token_admin_client.mint(&participant_addr, &1000); @@ -239,7 +239,7 @@ fn participant_can_withdraw_partial_funds() { sc.env.mock_all_auths(); - let participant_addr = Address::random(&sc.env); + let participant_addr = Address::generate(&sc.env); // Add funds to client address (as participant) sc.token_admin_client.mint(&participant_addr, &1000); @@ -282,7 +282,7 @@ fn participant_cannot_withdraw_more_partial_funds_than_it_has() { sc.env.mock_all_auths(); - let participant_addr = Address::random(&sc.env); + let participant_addr = Address::generate(&sc.env); // Add funds to client address (as participant) sc.token_admin_client.mint(&participant_addr, &1000); @@ -297,7 +297,7 @@ fn participant_can_deposit_extra_funds() { sc.env.mock_all_auths(); - let participant_addr = Address::random(&sc.env); + let participant_addr = Address::generate(&sc.env); // Add funds to client address (as participant) sc.token_admin_client.mint(&participant_addr, &1000); @@ -340,7 +340,7 @@ fn non_existent_participant_cannot_stake() { sc.env.mock_all_auths(); - sc.contract_client.withdraw(&Address::random(&sc.env), &1); + sc.contract_client.withdraw(&Address::generate(&sc.env), &1); } #[test] @@ -350,7 +350,7 @@ fn non_existent_participant_cannot_leave() { sc.env.mock_all_auths(); - sc.contract_client.leave(&Address::random(&sc.env)); + sc.contract_client.leave(&Address::generate(&sc.env)); } #[test] @@ -360,7 +360,7 @@ fn non_existent_participant_cannot_withdraw() { sc.env.mock_all_auths(); - sc.contract_client.leave(&Address::random(&sc.env)); + sc.contract_client.leave(&Address::generate(&sc.env)); } #[test] @@ -369,7 +369,7 @@ fn curator_can_whitelist_participant() { sc.env.mock_all_auths(); - let participant = &Address::random(&sc.env); + let participant = &Address::generate(&sc.env); sc.token_admin_client.mint(participant, &1000); sc.contract_client.join(participant, &200); @@ -405,7 +405,7 @@ fn not_existent_participant_cannot_create_proposals() { sc.env.mock_all_auths(); - let participant = &Address::random(&sc.env); + let participant = &Address::generate(&sc.env); let hash = BytesN::random(&sc.env); sc.contract_client @@ -419,7 +419,7 @@ fn non_whitelisted_participant_cannot_create_proposals() { sc.env.mock_all_auths(); - let participant = &Address::random(&sc.env); + let participant = &Address::generate(&sc.env); sc.token_admin_client.mint(participant, &1000); sc.contract_client.join(participant, &200); @@ -434,7 +434,7 @@ fn whitelisted_participant_can_create_proposals() { sc.env.mock_all_auths(); - let participant = Address::random(&sc.env); + let participant = Address::generate(&sc.env); sc.token_admin_client.mint(&participant, &1000); sc.contract_client.join(&participant, &200); @@ -468,7 +468,7 @@ fn whitelisted_participant_can_vote_proposals() { sc.env.mock_all_auths(); - let participant = Address::random(&sc.env); + let participant = Address::generate(&sc.env); sc.token_admin_client.mint(&participant, &1000); sc.contract_client.join(&participant, &200); @@ -500,7 +500,7 @@ fn non_whitelisted_participant_cant_vote_proposals() { sc.env.mock_all_auths(); - let participant = Address::random(&sc.env); + let participant = Address::generate(&sc.env); sc.token_admin_client.mint(&participant, &1000); sc.contract_client.join(&participant, &200); @@ -515,7 +515,7 @@ fn non_whitelisted_participant_cant_execute_proposals() { sc.env.mock_all_auths(); - let participant = Address::random(&sc.env); + let participant = Address::generate(&sc.env); sc.token_admin_client.mint(&participant, &1000); sc.contract_client.join(&participant, &200); @@ -530,8 +530,8 @@ fn only_author_can_execute_proposals() { sc.env.mock_all_auths(); - let participant_1 = Address::random(&sc.env); - let participant_2 = Address::random(&sc.env); + let participant_1 = Address::generate(&sc.env); + let participant_2 = Address::generate(&sc.env); sc.token_admin_client.mint(&participant_1, &1000); sc.token_admin_client.mint(&participant_2, &1000); @@ -563,8 +563,8 @@ fn whitelisted_participant_can_execute_standard_proposal() { sc.env.mock_all_auths(); - let participant_1 = Address::random(&sc.env); - let participant_2 = Address::random(&sc.env); + let participant_1 = Address::generate(&sc.env); + let participant_2 = Address::generate(&sc.env); sc.token_admin_client.mint(&participant_1, &1000); sc.token_admin_client.mint(&participant_2, &1000); @@ -622,7 +622,7 @@ fn proposals_can_only_be_executed_once() { sc.env.mock_all_auths(); - let participant_1 = Address::random(&sc.env); + let participant_1 = Address::generate(&sc.env); sc.token_admin_client.mint(&participant_1, &1000); sc.contract_client.join(&participant_1, &800); sc.contract_client.whitelist(&participant_1); @@ -659,7 +659,7 @@ fn execute_a_code_upgrade_proposal_flow() { .deployer() .upload_contract_wasm(Bytes::from_slice(&sc.env, &bytes)); - let participant_1 = Address::random(&sc.env); + let participant_1 = Address::generate(&sc.env); sc.token_admin_client.mint(&participant_1, &1000); @@ -686,7 +686,7 @@ fn execute_a_curator_change_flow() { sc.env.mock_all_auths(); - let participant_1 = Address::random(&sc.env); + let participant_1 = Address::generate(&sc.env); sc.token_admin_client.mint(&participant_1, &1000); @@ -713,9 +713,9 @@ fn join_can_only_be_called_when_initiliazed() { let env = Env::default(); env.mock_all_auths(); - let contract_id = env.register_contract(Some(&Address::random(&env)), GovernanceContract); + let contract_id = env.register_contract(Some(&Address::generate(&env)), GovernanceContract); let contract_client = GovernanceContractClient::new(&env, &contract_id); - contract_client.join(&Address::random(&env), &200); + contract_client.join(&Address::generate(&env), &200); } #[test] @@ -724,9 +724,9 @@ fn stake_can_only_be_called_when_initiliazed() { let env = Env::default(); env.mock_all_auths(); - let contract_id = env.register_contract(Some(&Address::random(&env)), GovernanceContract); + let contract_id = env.register_contract(Some(&Address::generate(&env)), GovernanceContract); let contract_client = GovernanceContractClient::new(&env, &contract_id); - contract_client.stake(&Address::random(&env), &200); + contract_client.stake(&Address::generate(&env), &200); } #[test] @@ -735,9 +735,9 @@ fn leave_can_only_be_called_when_initiliazed() { let env = Env::default(); env.mock_all_auths(); - let contract_id = env.register_contract(Some(&Address::random(&env)), GovernanceContract); + let contract_id = env.register_contract(Some(&Address::generate(&env)), GovernanceContract); let contract_client = GovernanceContractClient::new(&env, &contract_id); - contract_client.leave(&Address::random(&env)); + contract_client.leave(&Address::generate(&env)); } #[test] @@ -746,9 +746,9 @@ fn withdraw_can_only_be_called_when_initiliazed() { let env = Env::default(); env.mock_all_auths(); - let contract_id = env.register_contract(Some(&Address::random(&env)), GovernanceContract); + let contract_id = env.register_contract(Some(&Address::generate(&env)), GovernanceContract); let contract_client = GovernanceContractClient::new(&env, &contract_id); - contract_client.withdraw(&Address::random(&env), &100); + contract_client.withdraw(&Address::generate(&env), &100); } #[test] @@ -757,9 +757,9 @@ fn whitelist_can_only_be_called_when_initiliazed() { let env = Env::default(); env.mock_all_auths(); - let contract_id = env.register_contract(Some(&Address::random(&env)), GovernanceContract); + let contract_id = env.register_contract(Some(&Address::generate(&env)), GovernanceContract); let contract_client = GovernanceContractClient::new(&env, &contract_id); - contract_client.whitelist(&Address::random(&env)); + contract_client.whitelist(&Address::generate(&env)); } #[test] @@ -768,10 +768,10 @@ fn new_proposal_can_only_be_called_when_initiliazed() { let env = Env::default(); env.mock_all_auths(); - let contract_id = env.register_contract(Some(&Address::random(&env)), GovernanceContract); + let contract_id = env.register_contract(Some(&Address::generate(&env)), GovernanceContract); let contract_client = GovernanceContractClient::new(&env, &contract_id); contract_client.new_proposal( - &Address::random(&env), + &Address::generate(&env), &1, &shared::voting::ProposalPayload::Comment(BytesN::random(&env)), ); @@ -783,9 +783,9 @@ fn vote_can_only_be_called_when_initiliazed() { let env = Env::default(); env.mock_all_auths(); - let contract_id = env.register_contract(Some(&Address::random(&env)), GovernanceContract); + let contract_id = env.register_contract(Some(&Address::generate(&env)), GovernanceContract); let contract_client = GovernanceContractClient::new(&env, &contract_id); - contract_client.vote(&Address::random(&env), &1); + contract_client.vote(&Address::generate(&env), &1); } #[test] @@ -794,7 +794,7 @@ fn execute_proposal_can_only_be_called_when_initiliazed() { let env = Env::default(); env.mock_all_auths(); - let contract_id = env.register_contract(Some(&Address::random(&env)), GovernanceContract); + let contract_id = env.register_contract(Some(&Address::generate(&env)), GovernanceContract); let contract_client = GovernanceContractClient::new(&env, &contract_id); - contract_client.execute_proposal(&Address::random(&env), &1); + contract_client.execute_proposal(&Address::generate(&env), &1); } diff --git a/contracts/lottery/src/test.rs b/contracts/lottery/src/test.rs index 84a6b3a0..5cb9b589 100644 --- a/contracts/lottery/src/test.rs +++ b/contracts/lottery/src/test.rs @@ -286,7 +286,7 @@ fn users_can_buy_tickets() { &10, ); - let ticket_buyer = Address::random(&test_scenario.env); + let ticket_buyer = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer, &101); let ticket = vec![&test_scenario.env, 3, 5, 10, 20, 33]; @@ -315,7 +315,7 @@ fn users_can_buy_tickets() { fn tickets_cannot_be_bought_for_not_initialized_lottery() { let test_scenario = setup_test_scenario(); - let ticket_buyer = Address::random(&test_scenario.env); + let ticket_buyer = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer, &101); let ticket = vec![&test_scenario.env, 3, 5, 10, 20, 33]; @@ -338,8 +338,8 @@ fn tickets_cannot_be_bought_for_finished_lottery() { &2, ); - let ticket_buyer1 = Address::random(&test_scenario.env); - let ticket_buyer2 = Address::random(&test_scenario.env); + let ticket_buyer1 = Address::generate(&test_scenario.env); + let ticket_buyer2 = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer1, &200); test_scenario.test_token_client.mint(&ticket_buyer2, &101); @@ -368,7 +368,7 @@ fn ticket_should_have_the_same_number_of_numbers_as_defined_in_lottery() { &10, ); - let ticket_buyer = Address::random(&test_scenario.env); + let ticket_buyer = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer, &101); test_scenario.client.buy_ticket(&ticket_buyer, &vec![&test_scenario.env, 3, 5, 10, 20]); @@ -389,7 +389,7 @@ fn all_ticket_numbers_should_be_in_the_specified_range() { &10, ); - let ticket_buyer = Address::random(&test_scenario.env); + let ticket_buyer = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer, &101); test_scenario.client.buy_ticket(&ticket_buyer, &vec![&test_scenario.env, 1, 5, 10, 20, 51]); @@ -409,8 +409,8 @@ fn play_lottery_works_as_expected() { &2, ); - let ticket_buyer1 = Address::random(&test_scenario.env); - let ticket_buyer2 = Address::random(&test_scenario.env); + let ticket_buyer1 = Address::generate(&test_scenario.env); + let ticket_buyer2 = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer1, &101); test_scenario.test_token_client.mint(&ticket_buyer2, &101); @@ -467,8 +467,8 @@ fn lottery_cannot_be_played_if_finished() { &2, ); - let ticket_buyer1 = Address::random(&test_scenario.env); - let ticket_buyer2 = Address::random(&test_scenario.env); + let ticket_buyer1 = Address::generate(&test_scenario.env); + let ticket_buyer2 = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer1, &200); test_scenario.test_token_client.mint(&ticket_buyer2, &101); @@ -496,8 +496,8 @@ fn play_lottery_with_many_prizes_works_as_expected() { &2, ); - let ticket_buyer1 = Address::random(&test_scenario.env); - let ticket_buyer2 = Address::random(&test_scenario.env); + let ticket_buyer1 = Address::generate(&test_scenario.env); + let ticket_buyer2 = Address::generate(&test_scenario.env); // Transfer some funds to the buyer test_scenario.test_token_client.mint(&ticket_buyer1, &101); @@ -548,7 +548,7 @@ fn lottery_cannot_be_played_without_min_participants() { &2, ); - let ticket_buyer1 = Address::random(&test_scenario.env); + let ticket_buyer1 = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer1, &101); @@ -570,7 +570,7 @@ fn correct_lottery_results_are_returned() { &1, ); - let ticket_buyer1 = Address::random(&test_scenario.env); + let ticket_buyer1 = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer1, &101); @@ -602,7 +602,7 @@ fn should_not_return_results_for_wrong_lottery_number() { &1, ); - let ticket_buyer1 = Address::random(&test_scenario.env); + let ticket_buyer1 = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer1, &101); @@ -627,7 +627,7 @@ fn should_not_return_results_for_not_played_lottery() { &1, ); - let ticket_buyer1 = Address::random(&test_scenario.env); + let ticket_buyer1 = Address::generate(&test_scenario.env); test_scenario.test_token_client.mint(&ticket_buyer1, &101); @@ -660,9 +660,9 @@ fn get_winners_return_correct_winners() { let env = Env::default(); let result = draw_numbers::(&env, 50, 5, 666); let thresholds = map![&env, (5, 30), (4, 15), (3, 10)]; - let player1 = Address::random(&env); - let player2 = Address::random(&env); - let player3 = Address::random(&env); + let player1 = Address::generate(&env); + let player2 = Address::generate(&env); + let player3 = Address::generate(&env); let tickets = map![ &env, (player1.clone(), vec![&env, vec![&env, 22, 14, 35, 44, 29]]), @@ -683,9 +683,9 @@ fn count_total_prizes_percentage_counts_correctly() { let env = Env::default(); let (result, tickets, thresholds) = setup_additional_test_data( &env, - Address::random(&env), - Address::random(&env), - Address::random(&env), + Address::generate(&env), + Address::generate(&env), + Address::generate(&env), ); let winners = get_winners(&env, &result, &tickets, &thresholds); @@ -698,15 +698,15 @@ fn thresholds_are_properly_recalculated() { let env = Env::default(); let (result, mut tickets, mut thresholds) = setup_additional_test_data( &env, - Address::random(&env), - Address::random(&env), - Address::random(&env), + Address::generate(&env), + Address::generate(&env), + Address::generate(&env), ); - tickets.set(Address::random(&env), vec![&env, vec![&env, 22, 14, 35, 44, 29]]); - tickets.set(Address::random(&env), vec![&env, vec![&env, 22, 14, 1, 44, 29]]); - tickets.set(Address::random(&env), vec![&env, vec![&env, 22, 14, 35, 1, 2]]); - tickets.set(Address::random(&env), vec![&env, vec![&env, 22, 14, 3, 1, 2]]); + tickets.set(Address::generate(&env), vec![&env, vec![&env, 22, 14, 35, 44, 29]]); + tickets.set(Address::generate(&env), vec![&env, vec![&env, 22, 14, 1, 44, 29]]); + tickets.set(Address::generate(&env), vec![&env, vec![&env, 22, 14, 35, 1, 2]]); + tickets.set(Address::generate(&env), vec![&env, vec![&env, 22, 14, 3, 1, 2]]); // there are: // - 4 tickets with 5 hits @@ -727,9 +727,9 @@ fn thresholds_are_properly_recalculated() { #[test] fn prizes_are_properly_calculated_and_assigned() { let env = Env::default(); - let p1 = Address::random(&env); - let p2 = Address::random(&env); - let p3 = Address::random(&env); + let p1 = Address::generate(&env); + let p2 = Address::generate(&env); + let p3 = Address::generate(&env); let (result, tickets, mut thresholds) = setup_additional_test_data(&env, p1.clone(), p2.clone(), p3.clone()); let winners = get_winners(&env, &result, &tickets, &thresholds); @@ -773,7 +773,7 @@ fn setup_test_scenario<'a>() -> TestScenario<'a> { env.mock_all_auths(); let contract_id = env.register_contract(None, LotteryContract); let client = LotteryContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let token_addr = env.register_stellar_asset_contract(token_admin.clone()); let test_token_client = token::StellarAssetClient::new(&env, &token_addr); let token_client = token::Client::new(&env, &token_addr); diff --git a/contracts/marketplace/src/test.rs b/contracts/marketplace/src/test.rs index 33ff4e05..aa904db0 100644 --- a/contracts/marketplace/src/test.rs +++ b/contracts/marketplace/src/test.rs @@ -42,14 +42,14 @@ fn setup_test<'a>() -> ( let contract_client: MarketplaceContractClient<'_> = MarketplaceContractClient::new(&env, &contract_id); - let seller = Address::random(&env); - let buyer = Address::random(&env); + let seller = Address::generate(&env); + let buyer = Address::generate(&env); - let token_admin_client = create_token_asset(&env, &Address::random(&env)); + let token_admin_client = create_token_asset(&env, &Address::generate(&env)); let token_client = token::Client::new(&env, &token_admin_client.address); - contract_client.init(&token_client.address, &Address::random(&env)); - let asset_admin_client = create_token_asset(&env, &Address::random(&env)); + contract_client.init(&token_client.address, &Address::generate(&env)); + let asset_admin_client = create_token_asset(&env, &Address::generate(&env)); let asset_client = token::Client::new(&env, &asset_admin_client.address); ( @@ -77,7 +77,7 @@ fn cannot_initialize_marketplace_twice() { let contract_id = env.register_contract(None, MarketplaceContract); let client: MarketplaceContractClient<'_> = MarketplaceContractClient::new(&env, &contract_id); - let address = Address::random(&env); // Address just for satisfying interfaces. + let address = Address::generate(&env); // Address just for satisfying interfaces. client.init(&address, &address); client.init(&address, &address); } @@ -574,7 +574,7 @@ fn cannot_create_listing_without_initialize() { env.mock_all_auths(); let contract_id = env.register_contract(None, MarketplaceContract); let client: MarketplaceContractClient<'_> = MarketplaceContractClient::new(&env, &contract_id); - client.create_listing(&Address::random(&env), &Address::random(&env), &1, &1); + client.create_listing(&Address::generate(&env), &Address::generate(&env), &1, &1); } #[test] @@ -584,7 +584,7 @@ fn cannot_buy_listing_without_initialize() { env.mock_all_auths(); let contract_id = env.register_contract(None, MarketplaceContract); let client: MarketplaceContractClient<'_> = MarketplaceContractClient::new(&env, &contract_id); - client.buy_listing(&Address::random(&env), &1); + client.buy_listing(&Address::generate(&env), &1); } #[test] diff --git a/contracts/payment_splitter/src/test.rs b/contracts/payment_splitter/src/test.rs index e41f4a04..b2a11404 100644 --- a/contracts/payment_splitter/src/test.rs +++ b/contracts/payment_splitter/src/test.rs @@ -22,10 +22,10 @@ fn setup_test<'a>() -> (Env, PaymentSplitterContractClient<'a>) { fn cannot_initialize_twice() { let (env, client) = setup_test(); - let admin = Address::random(&env); + let admin = Address::generate(&env); let token = create_token_contract(&env, &admin); - let recipient_1 = Address::random(&env); - let recipient_2 = Address::random(&env); + let recipient_1 = Address::generate(&env); + let recipient_2 = Address::generate(&env); client.init( &admin, &token.address, @@ -45,11 +45,11 @@ fn create_token_contract<'a>(e: &Env, admin: &Address) -> token::StellarAssetCli #[test] fn splits_works() { let (env, client) = setup_test(); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); - let recipient_1 = Address::random(&env); - let recipient_2 = Address::random(&env); + let recipient_1 = Address::generate(&env); + let recipient_2 = Address::generate(&env); client.init( &token_admin, @@ -80,11 +80,11 @@ fn splits_works() { #[should_panic(expected = "Error(Contract, #4)")] fn splits_fails_if_not_enough_money() { let (env, client) = setup_test(); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); - let recipient_1 = Address::random(&env); - let recipient_2 = Address::random(&env); + let recipient_1 = Address::generate(&env); + let recipient_2 = Address::generate(&env); client.init( &token_admin, diff --git a/contracts/raffle/src/test.rs b/contracts/raffle/src/test.rs index a5395d4e..ea185507 100644 --- a/contracts/raffle/src/test.rs +++ b/contracts/raffle/src/test.rs @@ -17,7 +17,7 @@ fn admin_is_identified_on_init() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let target_token = create_token_contract(&env, &Address::random(&env)); + let target_token = create_token_contract(&env, &Address::generate(&env)); client.init(&client.address, &target_token.address, &2, &100); @@ -61,7 +61,7 @@ fn raffle_cannot_be_initialized_twice() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); client.init(&client.address, &test_token_client.address, &1, &100); @@ -76,7 +76,7 @@ fn raffle_cannot_be_initialized_without_winners() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); client.init(&client.address, &test_token_client.address, &0, &100); @@ -90,7 +90,7 @@ fn raffle_cannot_be_initialized_with_ticket_price_zero() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); client.init(&client.address, &test_token_client.address, &1, &0); @@ -127,12 +127,12 @@ fn buy_ticket_works_as_expected() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); client.init(&client.address, &test_token_client.address, &2, &100); - let ticket_buyer = Address::random(&env); + let ticket_buyer = Address::generate(&env); // Transfer some funds to the buyer test_token_client.mint(&ticket_buyer, &101); @@ -161,12 +161,12 @@ fn buy_ticket_panics_if_buyer_has_not_enough_funds() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); client.init(&client.address, &test_token_client.address, &2, &100); - let ticket_buyer = Address::random(&env); + let ticket_buyer = Address::generate(&env); // Transfer some funds to the buyer test_token_client.mint(&ticket_buyer, &100); @@ -182,12 +182,12 @@ fn buy_ticket_panics_if_invoked_after_raffle_is_played() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); client.init(&client.address, &test_token_client.address, &1, &100); - let ticket_buyer = Address::random(&env); + let ticket_buyer = Address::generate(&env); // Transfer some funds to the buyer test_token_client.mint(&ticket_buyer, &400); @@ -220,13 +220,13 @@ fn play_raffle_works() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); client.init(&client.address, &test_token_client.address, &1, &100); - let ticket_buyer_1 = Address::random(&env); - let ticket_buyer_2 = Address::random(&env); + let ticket_buyer_1 = Address::generate(&env); + let ticket_buyer_2 = Address::generate(&env); // Transfer some funds to the buyer test_token_client.mint(&ticket_buyer_1, &101); @@ -268,13 +268,13 @@ fn play_raffle_cannot_be_invoked_twice() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); client.init(&client.address, &test_token_client.address, &1, &100); - let ticket_buyer_1 = Address::random(&env); - let ticket_buyer_2 = Address::random(&env); + let ticket_buyer_1 = Address::generate(&env); + let ticket_buyer_2 = Address::generate(&env); // Transfer some funds to the buyer test_token_client.mint(&ticket_buyer_1, &101); @@ -295,7 +295,7 @@ fn raffle_cannot_be_played_if_not_enough_participants() { let contract_id = env.register_contract(None, RaffleContract); let client = RaffleContractClient::new(&env, &contract_id); - let token_admin = Address::random(&env); + let token_admin = Address::generate(&env); let test_token_client = create_token_contract(&env, &token_admin); client.init(&client.address, &test_token_client.address, &1, &100); diff --git a/contracts/shared/src/rand.rs b/contracts/shared/src/rand.rs index 6ed5c30b..86309292 100644 --- a/contracts/shared/src/rand.rs +++ b/contracts/shared/src/rand.rs @@ -18,6 +18,6 @@ impl RandomNumberGeneratorTrait for RandomNumberGenerator { } fn number(&mut self, env: &Env, max_range: u32) -> u32 { - env.prng().u64_in_range(1..=max_range as u64) as u32 + env.prng().gen_range::(1..=max_range as u64) as u32 } } diff --git a/contracts/simple_voting/src/test.rs b/contracts/simple_voting/src/test.rs index 604d4401..d3433edd 100644 --- a/contracts/simple_voting/src/test.rs +++ b/contracts/simple_voting/src/test.rs @@ -92,7 +92,7 @@ fn cannot_vote_if_voting_time_exceeded() { advance_ledger_time_in(3600, &mut env); - let result = proposal.vote(env.ledger().timestamp(), Address::random(&env)); + let result = proposal.vote(env.ledger().timestamp(), Address::generate(&env)); assert_eq!(Err(Error::VotingClosed), result) } @@ -103,8 +103,8 @@ fn cannot_vote_if_total_voters_reached() { let mut voters = Map::::new(&env); - voters.set(Address::random(&env), true); // Dummy voters - voters.set(Address::random(&env), true); // Dummy voters + voters.set(Address::generate(&env), true); // Dummy voters + voters.set(Address::generate(&env), true); // Dummy voters let mut proposal = Proposal { voting_end_time: env.ledger().timestamp() + 3600, @@ -114,7 +114,7 @@ fn cannot_vote_if_total_voters_reached() { total_voters: 2, }; - let result = proposal.vote(env.ledger().timestamp(), Address::random(&env)); + let result = proposal.vote(env.ledger().timestamp(), Address::generate(&env)); assert_eq!(Err(Error::VotingClosed), result) } @@ -140,7 +140,7 @@ fn proposal_calculate_approval_rate( let mut voters = Map::::new(&env); for _ in 0..votes { - voters.set(Address::random(&env), true); // Dummy voters + voters.set(Address::generate(&env), true); // Dummy voters } let proposal = Proposal { diff --git a/contracts/voting/src/test.rs b/contracts/voting/src/test.rs index 88e2182d..c8b94230 100644 --- a/contracts/voting/src/test.rs +++ b/contracts/voting/src/test.rs @@ -80,7 +80,7 @@ fn setup_test<'a>() -> (Env, ProposalVotingContractClient<'a>, Address) { let env = Env::default(); let contract_id = env.register_contract(None, ProposalVotingContract); let client = ProposalVotingContractClient::new(&env, &contract_id); - let admin = Address::random(&env); + let admin = Address::generate(&env); client.init(&admin, &3600, &50_00, &1000, &false); (env, client, admin) @@ -251,7 +251,7 @@ fn cannot_vote_if_voting_time_exceeded() { let (mut env, _, _) = setup_test(); let comment = BytesN::random(&env); - let proposer = Address::random(&env); + let proposer = Address::generate(&env); let mut proposal = Proposal { id: 1, @@ -266,7 +266,7 @@ fn cannot_vote_if_voting_time_exceeded() { advance_ledger_time_in(3600, &mut env); - let result = proposal.vote(env.ledger().timestamp(), Address::random(&env), 1); + let result = proposal.vote(env.ledger().timestamp(), Address::generate(&env), 1); assert_eq!(Err(Error::VotingClosed), result) } @@ -277,11 +277,11 @@ fn cannot_vote_if_total_voters_reached() { let mut voters = Map::::new(&env); - voters.set(Address::random(&env), true); // Dummy voters - voters.set(Address::random(&env), true); // Dummy voters + voters.set(Address::generate(&env), true); // Dummy voters + voters.set(Address::generate(&env), true); // Dummy voters let comment = BytesN::random(&env); - let proposer = Address::random(&env); + let proposer = Address::generate(&env); let mut proposal = Proposal { id: 1, @@ -294,7 +294,7 @@ fn cannot_vote_if_total_voters_reached() { total_participation: 2, }; - let result = proposal.vote(env.ledger().timestamp(), Address::random(&env), 1); + let result = proposal.vote(env.ledger().timestamp(), Address::generate(&env), 1); assert_eq!(Err(Error::VotingClosed), result) } @@ -320,7 +320,7 @@ fn proposal_calculate_approval_rate( let voters = Map::::new(&env); let comment = BytesN::random(&env); - let proposer = Address::random(&env); + let proposer = Address::generate(&env); let proposal = Proposal { id: 1, @@ -359,7 +359,7 @@ fn proposal_comment_is_accessible() { let (env, _, _) = setup_test(); env.mock_all_auths(); let payload = ProposalPayload::Comment(BytesN::random(&env)); - let proposer = Address::random(&env); + let proposer = Address::generate(&env); let proposal = Proposal { id: 112, @@ -382,15 +382,15 @@ fn proposal_total_participation_can_be_set_from_balance() { let mut voters = Map::::new(&env); - let voter_1 = Address::random(&env); - let voter_2 = Address::random(&env); + let voter_1 = Address::generate(&env); + let voter_2 = Address::generate(&env); voters.set(voter_1.clone(), true); // Only voter_1 votes in favour. let mut proposal = Proposal { id: 112, payload: ProposalPayload::Comment(BytesN::random(&env)), - proposer: Address::random(&env), + proposer: Address::generate(&env), voting_end_time: 123123, target_approval_rate_bps: 5000, // Half the participation is enough to approve. // Participation data is in zero values, as it will be calculated from provided balance. @@ -417,8 +417,8 @@ fn set_participation_from_balance_checks_all_local_addresses_exist_in_balance() let mut voters = Map::::new(&env); - let voter_1 = Address::random(&env); - let voter_2 = Address::random(&env); + let voter_1 = Address::generate(&env); + let voter_2 = Address::generate(&env); voters.set(voter_1.clone(), true); // Only voter_1 votes in favour. voters.set(voter_2.clone(), true); // Only voter_1 votes in favour. @@ -426,7 +426,7 @@ fn set_participation_from_balance_checks_all_local_addresses_exist_in_balance() let mut proposal = Proposal { id: 112, payload: ProposalPayload::Comment(BytesN::random(&env)), - proposer: Address::random(&env), + proposer: Address::generate(&env), voting_end_time: 123123, target_approval_rate_bps: 5000, // Half the participation is enough to approve. @@ -474,8 +474,8 @@ fn proposals_can_be_updated_only_by_admin() { &ProposalPayload::Comment(BytesN::random(&env)), ); - let voter_1 = Address::random(&env); - let voter_2 = Address::random(&env); + let voter_1 = Address::generate(&env); + let voter_2 = Address::generate(&env); client.vote(&voter_1, &1); client.vote(&voter_2, &1); @@ -513,7 +513,7 @@ fn proposals_can_be_updated_only_if_they_exist_first() { let proposal = Proposal { id: 112, payload: ProposalPayload::Comment(BytesN::random(&env)), - proposer: Address::random(&env), + proposer: Address::generate(&env), voting_end_time: 123123, target_approval_rate_bps: 5000, participation: 0, @@ -530,10 +530,10 @@ fn non_admin_user_cannot_vote_if_admin_mode_is_on() { let contract_id = env.register_contract(None, ProposalVotingContract); let client = ProposalVotingContractClient::new(&env, &contract_id); - let admin = Address::random(&env); + let admin = Address::generate(&env); client.init(&admin, &3600, &50_00, &1000, &true); - let proposer = Address::random(&env); + let proposer = Address::generate(&env); client.create_proposal( &proposer, &1, diff --git a/crates/nebula-importer/src/lib.rs b/crates/nebula-importer/src/lib.rs index bfc95f9b..e4ce4d4a 100644 --- a/crates/nebula-importer/src/lib.rs +++ b/crates/nebula-importer/src/lib.rs @@ -191,11 +191,11 @@ mod tests { jail.create_file( "Cargo.toml", r#" - [package.metadata.nebula.imports] + [imports] token = "ghcr.io/eigerco/nebula/contracts/token" "#, )?; - let config: Config = Figment::new() + let _config: Config = Figment::new() .merge(Toml::file("Cargo.toml")) .extract() .unwrap(); From 312d03b215a1dbf04be9d92dd50cc0e0605e0cdd Mon Sep 17 00:00:00 2001 From: Geoffrey Mureithi Date: Fri, 8 Dec 2023 15:25:32 +0300 Subject: [PATCH 2/2] fix: wrong emitted symbol --- contracts/raffle/src/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/raffle/src/test.rs b/contracts/raffle/src/test.rs index ea185507..61082908 100644 --- a/contracts/raffle/src/test.rs +++ b/contracts/raffle/src/test.rs @@ -253,7 +253,7 @@ fn play_raffle_works() { &env, ( contract_id.clone(), - (Symbol::new(&env, "winner"), &ticket_buyer_2).into_val(&env), + (Symbol::new(&env, "winner"), &ticket_buyer_1).into_val(&env), 200i128.into_val(&env) ) ]