Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Soroban Domain #9

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::<()>(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@earrietadev hi 👋 if you have time, could you help us out here? I am getting a failure calling Soroban Domain's contract here and I don't understand the backtrace. Thanks in advance!

HostError: Error(WasmVm, InvalidAction)

Event log (newest first):
   0: [Diagnostic Event] topics:[error, Error(WasmVm, InvalidAction)], data:"escalating error to panic"
   1: [Diagnostic Event] topics:[error, Error(WasmVm, InvalidAction)], data:["contract call failed", register, [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, "soroban-versioning", [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM], "github.com/file.toml", "2ef4f49fdd8fa9dc463f1f06a094c26b88710990"]]
   2: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM, topics:[error, Error(WasmVm, InvalidAction)], data:"caught error from function"
   3: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM, topics:[error, Error(WasmVm, InvalidAction)], data:"escalating error to panic"
   4: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM, topics:[error, Error(WasmVm, InvalidAction)], data:["contract call failed", set_record, [Bytes(736f726f62616e2d76657273696f6e696e67), Bytes(786c6d), CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, 31536000]]
   5: [Failed Diagnostic Event (not emitted)] contract:CATRNPHYKNXAPNLHEYH55REB6YSAJLGCPA4YM6L3WUKSZOPI77M2UMKI, topics:[error, Error(WasmVm, InvalidAction)], data:["VM call trapped: UnreachableCodeReached", set_record]
   6: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM, topics:[fn_call, Bytes(2716bcf8536e07b567260fdec481f62404acc2783986797bb5152cb9e8ffd9aa), set_record], data:[Bytes(736f726f62616e2d76657273696f6e696e67), Bytes(786c6d), CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, 31536000]
   7: [Diagnostic Event] topics:[fn_call, Bytes(0000000000000000000000000000000000000000000000000000000000000005), register], data:[CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, "soroban-versioning", [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM], "github.com/file.toml", "2ef4f49fdd8fa9dc463f1f06a094c26b88710990"]
   8: [Diagnostic Event] contract:CBUSYNQKASUYFWYC3M2GUEDMX4AIVWPALDBYJPNK6554BREHTGZ2IUNF, topics:[fn_return, mint], data:Void
   9: [Contract Event] contract:CBUSYNQKASUYFWYC3M2GUEDMX4AIVWPALDBYJPNK6554BREHTGZ2IUNF, topics:[mint, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, "aaa:GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGO6V"], data:10000000000000000
   10: [Diagnostic Event] topics:[fn_call, Bytes(692c360a04a982db02db346a106cbf008ad9e058c384bdaaf77bc0c48799b3a4), mint], data:[CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, 10000000000000000]
   11: [Diagnostic Event] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM, topics:[fn_return, init], data:Void
   12: [Diagnostic Event] topics:[fn_call, Bytes(0000000000000000000000000000000000000000000000000000000000000005), init], data:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAITA4
   13: [Diagnostic Event] contract:CATRNPHYKNXAPNLHEYH55REB6YSAJLGCPA4YM6L3WUKSZOPI77M2UMKI, topics:[fn_return, init], data:Void
   14: [Diagnostic Event] topics:[fn_call, Bytes(2716bcf8536e07b567260fdec481f62404acc2783986797bb5152cb9e8ffd9aa), init], data:[CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM, 100, CBUSYNQKASUYFWYC3M2GUEDMX4AIVWPALDBYJPNK6554BREHTGZ2IUNF, 31536000, [Bytes(786c6d), Bytes(7374656c6c6172), Bytes(77616c6c6574), Bytes(64616f)]]
   15: [Diagnostic Event] contract:CBUSYNQKASUYFWYC3M2GUEDMX4AIVWPALDBYJPNK6554BREHTGZ2IUNF, topics:[fn_return, set_admin], data:Void
   16: [Contract Event] contract:CBUSYNQKASUYFWYC3M2GUEDMX4AIVWPALDBYJPNK6554BREHTGZ2IUNF, topics:[set_admin, GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGO6V, "aaa:GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGO6V"], data:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4
   17: [Diagnostic Event] topics:[fn_call, Bytes(692c360a04a982db02db346a106cbf008ad9e058c384bdaaf77bc0c48799b3a4), set_admin], data:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4
   18: [Diagnostic Event] contract:CBUSYNQKASUYFWYC3M2GUEDMX4AIVWPALDBYJPNK6554BREHTGZ2IUNF, topics:[fn_return, init_asset], data:Void
   19: [Diagnostic Event] topics:[fn_call, Bytes(692c360a04a982db02db346a106cbf008ad9e058c384bdaaf77bc0c48799b3a4), init_asset], data:Bytes(0000000161616100000000000000000000000000000000000000000000000000000000000000000000000003)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tupui doing a quick review, one thing I noticed is that you're hashing the domain before passing it to the contract so you need to make sure the value is not higher than the limit which is 15 digits. Also the last value you're passing is a i32 but the contract is expecting a u64

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I really appreciate 🙏 I will try this out!

&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(),
tupui marked this conversation as resolved.
Show resolved Hide resolved
],
);
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);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registering here with the same address as mainnet

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
Loading