-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Undo breaking api change to registering tokens
- Loading branch information
1 parent
39d223c
commit 11bb481
Showing
3 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate as soroban_sdk; | ||
use soroban_sdk::{ | ||
contractclient, contracttype, testutils::AccountId as _, AccountId, Bytes, BytesN, Env, | ||
}; | ||
|
||
#[contractclient(name = "TokenClient")] | ||
pub trait Token { | ||
fn init(env: Env, admin: Identifier, metadata: TokenMetadata); | ||
fn name(env: Env) -> Bytes; | ||
} | ||
|
||
#[derive(Clone)] | ||
#[contracttype] | ||
pub enum Identifier { | ||
Account(AccountId), | ||
} | ||
|
||
#[derive(Clone)] | ||
#[contracttype] | ||
pub struct TokenMetadata { | ||
pub name: Bytes, | ||
pub symbol: Bytes, | ||
pub decimals: u32, | ||
} | ||
|
||
#[test] | ||
fn test_register_token() { | ||
let e = Env::default(); | ||
|
||
let contract_id = e.register_contract_token(None); | ||
let client = TokenClient::new(&e, &contract_id); | ||
|
||
client.init( | ||
&Identifier::Account(AccountId::random(&e)), | ||
&TokenMetadata { | ||
name: Bytes::from_slice(&e, b"testme"), | ||
decimals: 7, | ||
symbol: Bytes::from_slice(&e, &[]), | ||
}, | ||
); | ||
|
||
assert_eq!(client.name(), Bytes::from_slice(&e, b"testme")) | ||
} | ||
|
||
#[test] | ||
fn test_register_token_at_id() { | ||
let e = Env::default(); | ||
|
||
let contract_id = BytesN::from_array(&e, &[1; 32]); | ||
e.register_contract_token(&contract_id); | ||
let client = TokenClient::new(&e, &contract_id); | ||
|
||
client.init( | ||
&Identifier::Account(AccountId::random(&e)), | ||
&TokenMetadata { | ||
name: Bytes::from_slice(&e, b"testme"), | ||
decimals: 7, | ||
symbol: Bytes::from_slice(&e, &[]), | ||
}, | ||
); | ||
|
||
assert_eq!(client.name(), Bytes::from_slice(&e, b"testme")) | ||
} |