Skip to content

Commit

Permalink
Expose xdr types to register non-native assets (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
sisuresh authored Jan 9, 2023
1 parent 135c3c8 commit 38417ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 4 additions & 1 deletion soroban-sdk/src/xdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ pub use super::env::xdr::{
};

// XDR for ledger entries.
pub use super::env::xdr::{AccountEntry, AccountId, Asset};
pub use super::env::xdr::{
AccountEntry, AccountId, AlphaNum12, AlphaNum4, Asset, AssetCode12, AssetCode4, PublicKey,
Uint256,
};
22 changes: 19 additions & 3 deletions soroban-token-spec/src/tests/use_token_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,35 @@ impl TestContract {

#[test]
fn test() {
use soroban_sdk::xdr::Asset;
use soroban_sdk::xdr::{
AccountId, AlphaNum12, AlphaNum4, Asset, AssetCode12, AssetCode4, PublicKey, Uint256,
};

let env = Env::default();

let token_contract_id = env.register_stellar_asset_contract(Asset::Native);
let issuer = AccountId(PublicKey::PublicKeyTypeEd25519(Uint256([65u8; 32])));
let asset4 = Asset::CreditAlphanum4(AlphaNum4 {
asset_code: AssetCode4([66u8; 4]),
issuer: issuer.clone(),
});
let asset12 = Asset::CreditAlphanum12(AlphaNum12 {
asset_code: AssetCode12([1u8; 12]),
issuer,
});
let token_contract_id = env.register_stellar_asset_contract(asset4);
// We aren't using the asset12 contract. We just want to make sure the registration works.
env.register_stellar_asset_contract(asset12);

let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract(&contract_id, TestContract);
let client = TestContractClient::new(&env, &contract_id);
client.init(&token_contract_id);

let token_client = TokenClient::new(&env, &client.get_token());
assert_eq!(token_client.name(), "native".into_val(&env));
assert_eq!(
token_client.name(),
"BBBB:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA".into_val(&env)
);

let (id, _signer) = generate(&env);

Expand Down

0 comments on commit 38417ad

Please sign in to comment.