Skip to content

Commit

Permalink
Integrate Soroban Domain
Browse files Browse the repository at this point in the history
  • Loading branch information
tupui committed Jul 25, 2024
1 parent a7d1a54 commit 9290cbb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
Binary file not shown.
24 changes: 21 additions & 3 deletions contracts/versioning/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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()
Expand Down
48 changes: 45 additions & 3 deletions contracts/versioning/src/test.rs
Original file line number Diff line number Diff line change
@@ -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<Bytes> = 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);

Expand All @@ -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 = [
Expand Down

0 comments on commit 9290cbb

Please sign in to comment.