Skip to content

Commit

Permalink
chore: Upgrade contract initialization in tests to the new syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovipu committed Nov 23, 2024
1 parent 301f6f0 commit 2a27cf3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 45 deletions.
74 changes: 37 additions & 37 deletions contracts/loan_manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ mod tests {
e.budget().reset_default();
let admin = Address::generate(&e);

let contract_id = e.register_contract(None, LoanManager);
let contract_id = e.register(LoanManager, ());
let client = LoanManagerClient::new(&e, &contract_id);

assert!(client.try_initialize(&admin).is_ok());
Expand All @@ -507,7 +507,7 @@ mod tests {
e.budget().reset_default();
let admin = Address::generate(&e);

let contract_id = e.register_contract(None, LoanManager);
let contract_id = e.register(LoanManager, ());
let client = LoanManagerClient::new(&e, &contract_id);

client.initialize(&admin);
Expand All @@ -522,7 +522,7 @@ mod tests {
e.budget().reset_default();

let admin = Address::generate(&e);
let deployer_client = LoanManagerClient::new(&e, &e.register_contract(None, LoanManager));
let deployer_client = LoanManagerClient::new(&e, &e.register(LoanManager, ()));
deployer_client.initialize(&admin);

// Setup test token
Expand Down Expand Up @@ -556,7 +556,7 @@ mod tests {

let admin = Address::generate(&e);

let deployer_client = LoanManagerClient::new(&e, &e.register_contract(None, LoanManager));
let deployer_client = LoanManagerClient::new(&e, &e.register(LoanManager, ()));
deployer_client.initialize(&admin);

// Setup test token
Expand Down Expand Up @@ -600,7 +600,7 @@ mod tests {

// Register mock Reflector contract.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

// Mint the user some coins
let user = Address::generate(&e);
Expand All @@ -609,15 +609,15 @@ mod tests {
assert_eq!(collateral_token_client.balance(&user), 1000);

// Set up a loan pool with funds for borrowing.
let loan_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let loan_pool_id = e.register(loan_pool::WASM, ());
let loan_pool_client = loan_pool::Client::new(&e, &loan_pool_id);

// Set up a loan_pool for the collaterals.
let collateral_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let collateral_pool_id = e.register(loan_pool::WASM, ());
let collateral_pool_client = loan_pool::Client::new(&e, &collateral_pool_id);

// Register loan manager contract.
let contract_id = e.register_contract(None, LoanManager);
let contract_id = e.register(LoanManager, ());
let contract_client = LoanManagerClient::new(&e, &contract_id);

// ACT
Expand Down Expand Up @@ -667,7 +667,7 @@ mod tests {

// Register mock Reflector contract.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

// Mint the user some coins
let user = Address::generate(&e);
Expand All @@ -676,15 +676,15 @@ mod tests {
assert_eq!(collateral_token_client.balance(&user), 1_000_000);

// Set up a loan pool with funds for borrowing.
let loan_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let loan_pool_id = e.register(loan_pool::WASM, ());
let loan_pool_client = loan_pool::Client::new(&e, &loan_pool_id);

// Set up a loan_pool for the collaterals.
let collateral_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let collateral_pool_id = e.register(loan_pool::WASM, ());
let collateral_pool_client = loan_pool::Client::new(&e, &collateral_pool_id);

// Register loan manager contract.
let contract_id = e.register_contract(None, LoanManager);
let contract_id = e.register(LoanManager, ());
let contract_client = LoanManagerClient::new(&e, &contract_id);

// ACT
Expand Down Expand Up @@ -716,7 +716,7 @@ mod tests {

// A new instance of reflector mock needs to be created, they only live for one ledger.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

contract_client.add_interest();

Expand Down Expand Up @@ -760,7 +760,7 @@ mod tests {

// Register mock Reflector contract.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

// Mint the user some coins
let user = Address::generate(&e);
Expand All @@ -769,15 +769,15 @@ mod tests {
assert_eq!(collateral_token_client.balance(&user), 10_000_000);

// Set up a loan pool with funds for borrowing.
let loan_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let loan_pool_id = e.register(loan_pool::WASM, ());
let loan_pool_client = loan_pool::Client::new(&e, &loan_pool_id);

// Set up a loan_pool for the collaterals.
let collateral_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let collateral_pool_id = e.register(loan_pool::WASM, ());
let collateral_pool_client = loan_pool::Client::new(&e, &collateral_pool_id);

// Register loan manager contract.
let contract_id = e.register_contract(None, LoanManager);
let contract_id = e.register(LoanManager, ());
let contract_client = LoanManagerClient::new(&e, &contract_id);

// ACT
Expand Down Expand Up @@ -805,7 +805,7 @@ mod tests {

// A new instance of reflector mock needs to be created, they only live for one ledger.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

assert_eq!(contract_client.get_interest_rate(&loan_pool_id), 2_980_000);
}
Expand Down Expand Up @@ -843,7 +843,7 @@ mod tests {

// Register mock Reflector contract.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

// Mint the user some coins
let user = Address::generate(&e);
Expand All @@ -852,15 +852,15 @@ mod tests {
assert_eq!(collateral_token_client.balance(&user), 10_000_000);

// Set up a loan pool with funds for borrowing.
let loan_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let loan_pool_id = e.register(loan_pool::WASM, ());
let loan_pool_client = loan_pool::Client::new(&e, &loan_pool_id);

// Set up a loan_pool for the collaterals.
let collateral_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let collateral_pool_id = e.register(loan_pool::WASM, ());
let collateral_pool_client = loan_pool::Client::new(&e, &collateral_pool_id);

// Register loan manager contract.
let contract_id = e.register_contract(None, LoanManager);
let contract_id = e.register(LoanManager, ());
let contract_client = LoanManagerClient::new(&e, &contract_id);

// ACT
Expand Down Expand Up @@ -888,7 +888,7 @@ mod tests {

// A new instance of reflector mock needs to be created, they only live for one ledger.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

assert_eq!(contract_client.get_interest_rate(&loan_pool_id), 644_440);
}
Expand Down Expand Up @@ -921,7 +921,7 @@ mod tests {

// Register mock Reflector contract.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

// Mint the user some coins
let user = Address::generate(&e);
Expand All @@ -930,15 +930,15 @@ mod tests {
assert_eq!(collateral_token_client.balance(&user), 1_000_000);

// Set up a loan pool with funds for borrowing.
let loan_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let loan_pool_id = e.register(loan_pool::WASM, ());
let loan_pool_client = loan_pool::Client::new(&e, &loan_pool_id);

// Set up a loan_pool for the collaterals.
let collateral_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let collateral_pool_id = e.register(loan_pool::WASM, ());
let collateral_pool_client = loan_pool::Client::new(&e, &collateral_pool_id);

// Register loan manager contract.
let contract_id = e.register_contract(None, LoanManager);
let contract_id = e.register(LoanManager, ());
let contract_client = LoanManagerClient::new(&e, &contract_id);

// ACT
Expand Down Expand Up @@ -995,7 +995,7 @@ mod tests {

// Register mock Reflector contract.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

// Mint the user some coins
let user = Address::generate(&e);
Expand All @@ -1004,15 +1004,15 @@ mod tests {
assert_eq!(collateral_token_client.balance(&user), 1_000_000);

// Set up a loan pool with funds for borrowing.
let loan_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let loan_pool_id = e.register(loan_pool::WASM, ());
let loan_pool_client = loan_pool::Client::new(&e, &loan_pool_id);

// Set up a loan_pool for the collaterals.
let collateral_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let collateral_pool_id = e.register(loan_pool::WASM, ());
let collateral_pool_client = loan_pool::Client::new(&e, &collateral_pool_id);

// Register loan manager contract.
let contract_id = e.register_contract(None, LoanManager);
let contract_id = e.register(LoanManager, ());
let contract_client = LoanManagerClient::new(&e, &contract_id);

// ACT
Expand Down Expand Up @@ -1061,7 +1061,7 @@ mod tests {

// Register mock Reflector contract.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

// Mint the user some coins
let user = Address::generate(&e);
Expand All @@ -1070,15 +1070,15 @@ mod tests {
assert_eq!(collateral_token_client.balance(&user), 1_000_000);

// Set up a loan pool with funds for borrowing.
let loan_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let loan_pool_id = e.register(loan_pool::WASM, ());
let loan_pool_client = loan_pool::Client::new(&e, &loan_pool_id);

// Set up a loan_pool for the collaterals.
let collateral_pool_id = e.register_contract_wasm(None, loan_pool::WASM);
let collateral_pool_id = e.register(loan_pool::WASM, ());
let collateral_pool_client = loan_pool::Client::new(&e, &collateral_pool_id);

// Register loan manager contract.
let contract_id = e.register_contract(None, LoanManager);
let contract_id = e.register(LoanManager, ());
let contract_client = LoanManagerClient::new(&e, &contract_id);

// ACT
Expand Down Expand Up @@ -1108,7 +1108,7 @@ mod tests {

// A new instance of reflector mock needs to be created, they only live for one ledger.
let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

contract_client.add_interest();

Expand All @@ -1123,7 +1123,7 @@ mod tests {
});

let reflector_addr = Address::from_string(&String::from_str(&e, REFLECTOR_ADDRESS));
e.register_contract_wasm(&reflector_addr, oracle::WASM);
e.register_at(&reflector_addr, oracle::WASM, ());

contract_client.liquidate(&admin, &user, &5000);

Expand Down
14 changes: 7 additions & 7 deletions contracts/loan_pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ mod test {
let user = Address::generate(&e);
stellar_asset.mint(&user, &1000);

let contract_id = e.register_contract(None, LoanPoolContract);
let contract_id = e.register(LoanPoolContract, ());
let contract_client = LoanPoolContractClient::new(&e, &contract_id);

contract_client.initialize(
Expand All @@ -307,7 +307,7 @@ mod test {
let user = Address::generate(&e);
stellar_asset.mint(&user, &1000);

let contract_id = e.register_contract(None, LoanPoolContract);
let contract_id = e.register(LoanPoolContract, ());
let contract_client = LoanPoolContractClient::new(&e, &contract_id);
let amount: i128 = 100;

Expand Down Expand Up @@ -338,7 +338,7 @@ mod test {
ticker: Symbol::new(&e, "XLM"),
};

let contract_id = e.register_contract(None, LoanPoolContract);
let contract_id = e.register(LoanPoolContract, ());
let contract_client = LoanPoolContractClient::new(&e, &contract_id);
contract_client.initialize(
&Address::generate(&e),
Expand Down Expand Up @@ -376,7 +376,7 @@ mod test {
let user = Address::generate(&e);
stellar_asset.mint(&user, &1000);

let contract_id = e.register_contract(None, LoanPoolContract);
let contract_id = e.register(LoanPoolContract, ());
let contract_client = LoanPoolContractClient::new(&e, &contract_id);
let amount: i128 = 100;

Expand Down Expand Up @@ -410,7 +410,7 @@ mod test {
let user = Address::generate(&e);
stellar_asset.mint(&user, &1000);

let contract_id = e.register_contract(None, LoanPoolContract);
let contract_id = e.register(LoanPoolContract, ());
let contract_client = LoanPoolContractClient::new(&e, &contract_id);
let amount: i128 = 2000;

Expand Down Expand Up @@ -440,7 +440,7 @@ mod test {
let user = Address::generate(&e);
stellar_asset.mint(&user, &1000);

let contract_id = e.register_contract(None, LoanPoolContract);
let contract_id = e.register(LoanPoolContract, ());
let contract_client = LoanPoolContractClient::new(&e, &contract_id);
let amount: i128 = 100;

Expand Down Expand Up @@ -476,7 +476,7 @@ mod test {
let user2 = Address::generate(&e);
stellar_asset.mint(&user2, &1000);

let contract_id = e.register_contract(None, LoanPoolContract);
let contract_id = e.register(LoanPoolContract, ());
let contract_client = LoanPoolContractClient::new(&e, &contract_id);
let amount: i128 = 100;

Expand Down
2 changes: 1 addition & 1 deletion contracts/reflector/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn init_contract_with_admin<'a>() -> (Env, PriceOracleContractClient<'a>, Config
"CDXHQTB7FGRMWTLJJLNI3XPKVC6SZDB5SFGZUYDPEGQQNC4G6CKE4QRC",
));

env.register_contract(contract_id, PriceOracleContract);
env.register_at(contract_id, PriceOracleContract, ());
let client: PriceOracleContractClient<'a> = PriceOracleContractClient::new(&env, contract_id);

env.budget().reset_unlimited();
Expand Down

0 comments on commit 2a27cf3

Please sign in to comment.