Skip to content

Commit

Permalink
Pass domain contract ID to register function
Browse files Browse the repository at this point in the history
  • Loading branch information
tupui committed Jul 28, 2024
1 parent 3836108 commit 04cea5e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
9 changes: 4 additions & 5 deletions contracts/versioning/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![no_std]

const CONTRACT_DOMAIN_ID: &str = "CATRNPHYKNXAPNLHEYH55REB6YSAJLGCPA4YM6L3WUKSZOPI77M2UMKI";

use soroban_sdk::{
contract, contractimpl, contracttype, panic_with_error, symbol_short, Address, Bytes, BytesN,
Env, IntoVal, String, Symbol, Vec,
Expand Down Expand Up @@ -73,6 +71,7 @@ impl Versioning {
maintainers: Vec<Address>,
url: String,
hash: String,
domain_contract_id: Address,
) -> Bytes {
let project = Project {
name: name.clone(),
Expand Down Expand Up @@ -100,12 +99,12 @@ impl Versioning {
} 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);
// domain_register(&env, &name_b, &maintainer, domain_contract_id);

let tld = Bytes::from_slice(&env, &[120, 108, 109]); // xlm
let min_duration: u64 = 31536000;
env.invoke_contract::<()>(
&contract_domain_id,
&domain_contract_id,
&Symbol::new(&env, "set_record"),
(
name_b,
Expand Down
39 changes: 29 additions & 10 deletions contracts/versioning/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![cfg(test)]

use super::{ContractErrors, Versioning, VersioningClient, CONTRACT_DOMAIN_ID};
use super::{ContractErrors, Versioning, VersioningClient};
use soroban_sdk::testutils::Address as _;
use soroban_sdk::{
symbol_short, testutils::Events, token, vec, Address, Bytes, Env, IntoVal, String, Vec,
};

mod contract_domain {
mod domain_contract {
soroban_sdk::contractimport!(
file = "../domain_3ebbeec072f4996958d4318656186732773ab5f0c159dcf039be202b4ecb8af8.wasm"
);
Expand All @@ -18,10 +18,8 @@ fn test() {
env.mock_all_auths();

// 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 domain_contract_id = env.register_contract_wasm(None, domain_contract::WASM);
let domain_contract = domain_contract::Client::new(&env, &domain_contract_id);

let adm: Address = Address::generate(&env);
let node_rate: u128 = 100;
Expand All @@ -40,7 +38,7 @@ fn test() {
let col_asset_client = token::TokenClient::new(&env, &token_address);
let col_asset_stellar = token::StellarAssetClient::new(&env, &token_address);

contract_domain.init(
domain_contract.init(
&adm,
&node_rate,
&col_asset_client.address.clone(),
Expand All @@ -65,7 +63,14 @@ fn test() {
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 id = contract.register(
&grogu,
&name,
&maintainers,
&url,
&hash,
&domain_contract_id,
);

let expected_id = [
55, 174, 131, 192, 111, 222, 16, 67, 114, 71, 67, 51, 90, 194, 243, 145, 147, 7, 137, 46,
Expand Down Expand Up @@ -106,7 +111,14 @@ fn test() {

// double registration
let error = contract
.try_register(&grogu, &name, &maintainers, &url, &hash)
.try_register(
&grogu,
&name,
&maintainers,
&url,
&hash,
&domain_contract_id,
)
.unwrap_err()
.unwrap();

Expand All @@ -118,7 +130,14 @@ fn test() {
"soroban-versioningsoroban-versioningsoroban-versioningsoroban-versioning",
);
let error = contract
.try_register(&grogu, &name_long, &maintainers, &url, &hash)
.try_register(
&grogu,
&name_long,
&maintainers,
&url,
&hash,
&domain_contract_id,
)
.unwrap_err()
.unwrap();

Expand Down

0 comments on commit 04cea5e

Please sign in to comment.