Skip to content

Commit

Permalink
Remove unnecessarily hardcoded contract IDs (stellar#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Oct 6, 2022
1 parent bd2a5f3 commit a431df5
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 41 deletions.
5 changes: 2 additions & 3 deletions auth/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

use super::*;

use soroban_sdk::{testutils::Accounts, Address, BytesN, Env};
use soroban_sdk::{testutils::Accounts, Address, Env};

#[test]
fn test() {
let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract(&contract_id, ExampleContract);
let contract_id = env.register_contract(None, ExampleContract);
let client = ExampleContractClient::new(&env, contract_id);

// Initialize contract by setting the admin.
Expand Down
10 changes: 3 additions & 7 deletions cross_contract/contract_b/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#![cfg(test)]

use crate::{contract_a, ContractB, ContractBClient};
use soroban_sdk::{BytesN, Env};
use soroban_sdk::Env;

#[test]
fn test() {
let env = Env::default();

// Define IDs for contract A and B.
let contract_a_id = BytesN::from_array(&env, &[0; 32]);
let contract_b_id = BytesN::from_array(&env, &[1; 32]);

// Register contract A using the imported WASM.
env.register_contract_wasm(&contract_a_id, contract_a::WASM);
let contract_a_id = env.register_contract_wasm(None, contract_a::WASM);

// Register contract B defined in this crate.
env.register_contract(&contract_b_id, ContractB);
let contract_b_id = env.register_contract(None, ContractB);

// Create a client for calling contract B.
let client = ContractBClient::new(&env, &contract_b_id);
Expand Down
5 changes: 2 additions & 3 deletions custom_types/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![cfg(test)]

use super::*;
use soroban_sdk::{BytesN, Env};
use soroban_sdk::Env;

#[test]
fn test() {
let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract(&contract_id, CustomTypesContract);
let contract_id = env.register_contract(None, CustomTypesContract);
let client = CustomTypesContractClient::new(&env, &contract_id);

assert_eq!(client.retrieve(), Name::None);
Expand Down
5 changes: 2 additions & 3 deletions events/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![cfg(test)]

use super::*;
use soroban_sdk::{symbol, BytesN, Env};
use soroban_sdk::{symbol, Env};

#[test]
fn test() {
let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract(&contract_id, EventsContract);
let contract_id = env.register_contract(None, EventsContract);
let client = EventsContractClient::new(&env, &contract_id);

client.hello(&symbol!("Dev"));
Expand Down
5 changes: 2 additions & 3 deletions hello_world/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![cfg(test)]

use super::*;
use soroban_sdk::{symbol, vec, BytesN, Env};
use soroban_sdk::{symbol, vec, Env};

#[test]
fn test() {
let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract(&contract_id, HelloContract);
let contract_id = env.register_contract(None, HelloContract);
let client = HelloContractClient::new(&env, &contract_id);

let words = client.hello(&symbol!("Dev"));
Expand Down
5 changes: 2 additions & 3 deletions increment/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![cfg(test)]

use super::{IncrementContract, IncrementContractClient};
use soroban_sdk::{BytesN, Env};
use soroban_sdk::Env;

#[test]
fn test() {
let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract(&contract_id, IncrementContract);
let contract_id = env.register_contract(None, IncrementContract);
let client = IncrementContractClient::new(&env, &contract_id);

assert_eq!(client.increment(), 1);
Expand Down
5 changes: 2 additions & 3 deletions logging/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#![cfg(test)]

use super::*;
use soroban_sdk::{symbol, testutils::Logger, BytesN, Env};
use soroban_sdk::{symbol, testutils::Logger, Env};

extern crate std;

#[test]
fn test() {
let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract(&contract_id, Contract);
let contract_id = env.register_contract(None, Contract);
let client = ContractClient::new(&env, &contract_id);

client.hello(&symbol!("Dev"));
Expand Down
6 changes: 2 additions & 4 deletions single_offer/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ fn generate_contract_id() -> [u8; 32] {
}

fn create_token_contract(e: &Env, admin: &AccountId) -> ([u8; 32], token::Client) {
let id = generate_contract_id();
let contract_id = BytesN::from_array(e, &id);
e.register_contract_token(&contract_id);
let id = e.register_contract_token(None);
let token = token::Client::new(e, &id);
// decimals, name, symbol don't matter in tests
token.init(
Expand All @@ -26,7 +24,7 @@ fn create_token_contract(e: &Env, admin: &AccountId) -> ([u8; 32], token::Client
decimals: 7,
},
);
(id, token)
(id.into(), token)
}

fn create_single_offer_contract(
Expand Down
6 changes: 2 additions & 4 deletions single_offer_router/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ fn generate_contract_id() -> [u8; 32] {
}

fn create_token_contract(e: &Env, admin: &AccountId) -> ([u8; 32], token::Client) {
let id = generate_contract_id();
let contract_id = BytesN::from_array(e, &id);
e.register_contract_token(&contract_id);
let id = e.register_contract_token(None);
let token = token::Client::new(e, &id);
// decimals, name, symbol don't matter in tests
token.init(
Expand All @@ -26,7 +24,7 @@ fn create_token_contract(e: &Env, admin: &AccountId) -> ([u8; 32], token::Client
decimals: 7,
},
);
(id, token)
(id.into(), token)
}

fn create_single_offer_router_contract(
Expand Down
6 changes: 2 additions & 4 deletions single_offer_xfer_from/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ fn generate_contract_id() -> [u8; 32] {
}

fn create_token_contract(e: &Env, admin: &AccountId) -> ([u8; 32], token::Client) {
let id = generate_contract_id();
let contract_id = BytesN::from_array(e, &id);
e.register_contract_token(&contract_id);
let id = e.register_contract_token(None);
let token = token::Client::new(e, &id);
// decimals, name, symbol don't matter in tests
token.init(
Expand All @@ -26,7 +24,7 @@ fn create_token_contract(e: &Env, admin: &AccountId) -> ([u8; 32], token::Client
decimals: 7,
},
);
(id, token)
(id.into(), token)
}

fn create_single_offer_contract(
Expand Down
6 changes: 2 additions & 4 deletions timelock/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ fn generate_contract_id() -> [u8; 32] {
}

fn create_token_contract(e: &Env, admin: &AccountId) -> (BytesN<32>, TokenClient) {
let id = generate_contract_id();
let contract_id = BytesN::from_array(e, &id);
e.register_contract_token(&contract_id);
let id = e.register_contract_token(None);
let token = TokenClient::new(e, &id);
// decimals, name, symbol don't matter in tests
token.init(
Expand All @@ -27,7 +25,7 @@ fn create_token_contract(e: &Env, admin: &AccountId) -> (BytesN<32>, TokenClient
decimals: 7,
},
);
(BytesN::from_array(&e, &id), token)
(id, token)
}

fn create_claimable_balance_contract(e: &Env) -> ClaimableBalanceContractClient {
Expand Down

0 comments on commit a431df5

Please sign in to comment.