diff --git a/contracts/domain_3ebbeec072f4996958d4318656186732773ab5f0c159dcf039be202b4ecb8af8.wasm b/contracts/domain_3ebbeec072f4996958d4318656186732773ab5f0c159dcf039be202b4ecb8af8.wasm new file mode 100644 index 0000000..c500f57 Binary files /dev/null and b/contracts/domain_3ebbeec072f4996958d4318656186732773ab5f0c159dcf039be202b4ecb8af8.wasm differ diff --git a/contracts/versioning/src/lib.rs b/contracts/versioning/src/lib.rs index d8e2635..fa4be1c 100755 --- a/contracts/versioning/src/lib.rs +++ b/contracts/versioning/src/lib.rs @@ -1,12 +1,14 @@ #![no_std] +const CONTRACT_DOMAIN_ID: &str = "CATRNPHYKNXAPNLHEYH55REB6YSAJLGCPA4YM6L3WUKSZOPI77M2UMKI"; + use soroban_sdk::{ - contract, contractimpl, contracttype, panic_with_error, symbol_short, Address, Bytes, BytesN, - Env, String, Vec, + contract, contractimpl, contracttype, panic_with_error, symbol_short, vec, Address, Bytes, + BytesN, Env, String, Symbol, Val, Vec, }; use soroban_sdk::{contracterror, contractmeta}; -contractmeta!(key = "Description", val = "Soroban Versioning"); +contractmeta!(key = "Description", val = "Tansu - Soroban Versioning"); #[contracterror] #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] @@ -97,6 +99,22 @@ impl Versioning { panic_with_error!(&env, &ContractErrors::ProjectAlreadyExist); } else { auth_maintainers(&env, &maintainer, &project.maintainers); + + let contract_domain_id_str = String::from_str(&env, CONTRACT_DOMAIN_ID); + let contract_domain_id = Address::from_string(&contract_domain_id_str); + let tld = Bytes::from_slice(&env, &[120, 108, 109]); // xlm + env.invoke_contract::<()>( + &contract_domain_id, + &Symbol::new(&env, "set_record"), + vec![ + &env, + name_b.to_val(), + tld.to_val(), + maintainer.to_val(), + maintainer.to_val(), + Val::from_i32(31536000).into(), + ], + ); env.storage().persistent().set(&key_, &project); env.events() diff --git a/contracts/versioning/src/test.rs b/contracts/versioning/src/test.rs index c56ba45..76e1a39 100755 --- a/contracts/versioning/src/test.rs +++ b/contracts/versioning/src/test.rs @@ -1,17 +1,56 @@ #![cfg(test)] -use super::{ContractErrors, Versioning, VersioningClient}; +use super::{ContractErrors, Versioning, VersioningClient, CONTRACT_DOMAIN_ID}; use soroban_sdk::testutils::Address as _; -use soroban_sdk::{symbol_short, testutils::Events, vec, Address, Bytes, Env, IntoVal, String}; +use soroban_sdk::{ + symbol_short, testutils::Events, token, vec, Address, Bytes, Env, IntoVal, String, Vec, +}; // use soroban_sdk::testutils::arbitrary::std::println; +mod contract_domain { + soroban_sdk::contractimport!( + file = "../domain_3ebbeec072f4996958d4318656186732773ab5f0c159dcf039be202b4ecb8af8.wasm" + ); +} + #[test] fn test() { let env = Env::default(); env.mock_all_auths(); - let contract_admin = Address::generate(&env); + // setup for Soroban Domain + let contract_domain_id_str = String::from_str(&env, CONTRACT_DOMAIN_ID); + let contract_domain_id = Address::from_string(&contract_domain_id_str); + env.register_contract_wasm(&contract_domain_id, contract_domain::WASM); + let contract_domain = contract_domain::Client::new(&env, &contract_domain_id); + + let adm: Address = Address::generate(&env); + let node_rate: u128 = 100; + let min_duration: u64 = 31536000; + let allowed_tlds: Vec = Vec::from_array( + &env, + [ + Bytes::from_slice(&env, "xlm".as_bytes()), + Bytes::from_slice(&env, "stellar".as_bytes()), + Bytes::from_slice(&env, "wallet".as_bytes()), + Bytes::from_slice(&env, "dao".as_bytes()), + ], + ); + let issuer: Address = Address::generate(&env); + let token_address = env.register_stellar_asset_contract(issuer.clone()); + let col_asset_client = token::TokenClient::new(&env, &token_address); + let col_asset_stellar = token::StellarAssetClient::new(&env, &token_address); + + contract_domain.init( + &adm, + &node_rate, + &col_asset_client.address.clone(), + &min_duration, + &allowed_tlds, + ); + // setup for Tansu + let contract_admin = Address::generate(&env); let contract_id = env.register_contract(None, Versioning); let contract = VersioningClient::new(&env, &contract_id); @@ -24,6 +63,9 @@ fn test() { let mando = Address::generate(&env); let maintainers = vec![&env, grogu.clone(), mando.clone()]; + let genesis_amount: i128 = 1_000_000_000 * 10_000_000; + col_asset_stellar.mint(&grogu, &genesis_amount); + let id = contract.register(&grogu, &name, &maintainers, &url, &hash); let expected_id = [