mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-07-25 23:23:11 +00:00
Merge branch 'main' into marvin/nonce
This commit is contained in:
@@ -4,6 +4,9 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
nssa_core.workspace = true
|
||||
token_core.workspace = true
|
||||
|
||||
@@ -4,6 +4,9 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
nssa_core.workspace = true
|
||||
serde.workspace = true
|
||||
|
||||
@@ -26,7 +26,7 @@ pub enum Instruction {
|
||||
amm_program_id: ProgramId,
|
||||
},
|
||||
|
||||
/// Adds liquidity to the Pool
|
||||
/// Adds liquidity to the Pool.
|
||||
///
|
||||
/// Required accounts:
|
||||
/// - AMM Pool (initialized)
|
||||
@@ -42,7 +42,7 @@ pub enum Instruction {
|
||||
max_amount_to_add_token_b: u128,
|
||||
},
|
||||
|
||||
/// Removes liquidity from the Pool
|
||||
/// Removes liquidity from the Pool.
|
||||
///
|
||||
/// Required accounts:
|
||||
/// - AMM Pool (initialized)
|
||||
@@ -85,11 +85,11 @@ pub struct PoolDefinition {
|
||||
pub liquidity_pool_supply: u128,
|
||||
pub reserve_a: u128,
|
||||
pub reserve_b: u128,
|
||||
/// Fees are currently not used
|
||||
/// Fees are currently not used.
|
||||
pub fees: u128,
|
||||
/// A pool becomes inactive (active = false)
|
||||
/// once all of its liquidity has been removed (e.g., reserves are emptied and
|
||||
/// liquidity_pool_supply = 0)
|
||||
/// `liquidity_pool_supply` = 0).
|
||||
pub active: bool,
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ impl TryFrom<&Data> for PoolDefinition {
|
||||
type Error = std::io::Error;
|
||||
|
||||
fn try_from(data: &Data) -> Result<Self, Self::Error> {
|
||||
PoolDefinition::try_from_slice(data.as_ref())
|
||||
Self::try_from_slice(data.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,10 +109,11 @@ impl From<&PoolDefinition> for Data {
|
||||
BorshSerialize::serialize(definition, &mut data)
|
||||
.expect("Serialization to Vec should not fail");
|
||||
|
||||
Data::try_from(data).expect("Token definition encoded data should fit into Data")
|
||||
Self::try_from(data).expect("Token definition encoded data should fit into Data")
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn compute_pool_pda(
|
||||
amm_program_id: ProgramId,
|
||||
definition_token_a_id: AccountId,
|
||||
@@ -124,11 +125,12 @@ pub fn compute_pool_pda(
|
||||
))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn compute_pool_pda_seed(
|
||||
definition_token_a_id: AccountId,
|
||||
definition_token_b_id: AccountId,
|
||||
) -> PdaSeed {
|
||||
use risc0_zkvm::sha::{Impl, Sha256};
|
||||
use risc0_zkvm::sha::{Impl, Sha256 as _};
|
||||
|
||||
let (token_1, token_2) = match definition_token_a_id
|
||||
.value()
|
||||
@@ -151,6 +153,7 @@ pub fn compute_pool_pda_seed(
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn compute_vault_pda(
|
||||
amm_program_id: ProgramId,
|
||||
pool_id: AccountId,
|
||||
@@ -162,8 +165,9 @@ pub fn compute_vault_pda(
|
||||
))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn compute_vault_pda_seed(pool_id: AccountId, definition_token_id: AccountId) -> PdaSeed {
|
||||
use risc0_zkvm::sha::{Impl, Sha256};
|
||||
use risc0_zkvm::sha::{Impl, Sha256 as _};
|
||||
|
||||
let mut bytes = [0; 64];
|
||||
bytes[0..32].copy_from_slice(&pool_id.to_bytes());
|
||||
@@ -177,12 +181,14 @@ pub fn compute_vault_pda_seed(pool_id: AccountId, definition_token_id: AccountId
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn compute_liquidity_token_pda(amm_program_id: ProgramId, pool_id: AccountId) -> AccountId {
|
||||
AccountId::from((&amm_program_id, &compute_liquidity_token_pda_seed(pool_id)))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn compute_liquidity_token_pda_seed(pool_id: AccountId) -> PdaSeed {
|
||||
use risc0_zkvm::sha::{Impl, Sha256};
|
||||
use risc0_zkvm::sha::{Impl, Sha256 as _};
|
||||
|
||||
let mut bytes = [0; 64];
|
||||
bytes[0..32].copy_from_slice(&pool_id.to_bytes());
|
||||
|
||||
@@ -7,6 +7,7 @@ use nssa_core::{
|
||||
};
|
||||
|
||||
#[expect(clippy::too_many_arguments, reason = "TODO: Fix later")]
|
||||
#[must_use]
|
||||
pub fn add_liquidity(
|
||||
pool: AccountWithMetadata,
|
||||
vault_a: AccountWithMetadata,
|
||||
@@ -123,7 +124,7 @@ pub fn add_liquidity(
|
||||
);
|
||||
|
||||
// 5. Update pool account
|
||||
let mut pool_post = pool.account.clone();
|
||||
let mut pool_post = pool.account;
|
||||
let pool_post_definition = PoolDefinition {
|
||||
liquidity_pool_supply: pool_def_data.liquidity_pool_supply + delta_lp,
|
||||
reserve_a: pool_def_data.reserve_a + actual_amount_a,
|
||||
@@ -155,7 +156,7 @@ pub fn add_liquidity(
|
||||
pool_definition_lp_auth.is_authorized = true;
|
||||
let call_token_lp = ChainedCall::new(
|
||||
token_program_id,
|
||||
vec![pool_definition_lp_auth.clone(), user_holding_lp.clone()],
|
||||
vec![pool_definition_lp_auth, user_holding_lp.clone()],
|
||||
&token_core::Instruction::Mint {
|
||||
amount_to_mint: delta_lp,
|
||||
},
|
||||
@@ -166,12 +167,12 @@ pub fn add_liquidity(
|
||||
|
||||
let post_states = vec![
|
||||
AccountPostState::new(pool_post),
|
||||
AccountPostState::new(vault_a.account.clone()),
|
||||
AccountPostState::new(vault_b.account.clone()),
|
||||
AccountPostState::new(pool_definition_lp.account.clone()),
|
||||
AccountPostState::new(user_holding_a.account.clone()),
|
||||
AccountPostState::new(user_holding_b.account.clone()),
|
||||
AccountPostState::new(user_holding_lp.account.clone()),
|
||||
AccountPostState::new(vault_a.account),
|
||||
AccountPostState::new(vault_b.account),
|
||||
AccountPostState::new(pool_definition_lp.account),
|
||||
AccountPostState::new(user_holding_a.account),
|
||||
AccountPostState::new(user_holding_b.account),
|
||||
AccountPostState::new(user_holding_lp.account),
|
||||
];
|
||||
|
||||
(post_states, chained_calls)
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
//! The AMM Program implementation.
|
||||
|
||||
#![expect(
|
||||
clippy::arithmetic_side_effects,
|
||||
clippy::integer_division,
|
||||
clippy::integer_division_remainder_used,
|
||||
reason = "TODO: Fix later"
|
||||
)]
|
||||
|
||||
pub use amm_core as core;
|
||||
|
||||
pub mod add;
|
||||
|
||||
@@ -10,6 +10,7 @@ use nssa_core::{
|
||||
};
|
||||
|
||||
#[expect(clippy::too_many_arguments, reason = "TODO: Fix later")]
|
||||
#[must_use]
|
||||
pub fn new_definition(
|
||||
pool: AccountWithMetadata,
|
||||
vault_a: AccountWithMetadata,
|
||||
@@ -79,8 +80,20 @@ pub fn new_definition(
|
||||
// LP Token minting calculation
|
||||
let initial_lp = (token_a_amount.get() * token_b_amount.get()).isqrt();
|
||||
|
||||
// Chain call for liquidity token (TokenLP definition -> User LP Holding)
|
||||
let instruction = if pool.account == Account::default() {
|
||||
token_core::Instruction::NewFungibleDefinition {
|
||||
name: String::from("LP Token"),
|
||||
total_supply: initial_lp,
|
||||
}
|
||||
} else {
|
||||
token_core::Instruction::Mint {
|
||||
amount_to_mint: initial_lp,
|
||||
}
|
||||
};
|
||||
|
||||
// Update pool account
|
||||
let mut pool_post = pool.account.clone();
|
||||
let mut pool_post = pool.account;
|
||||
let pool_post_definition = PoolDefinition {
|
||||
definition_token_a_id,
|
||||
definition_token_b_id,
|
||||
@@ -90,16 +103,12 @@ pub fn new_definition(
|
||||
liquidity_pool_supply: initial_lp,
|
||||
reserve_a: token_a_amount.into(),
|
||||
reserve_b: token_b_amount.into(),
|
||||
fees: 0u128, // TODO: we assume all fees are 0 for now.
|
||||
fees: 0_u128, // TODO: we assume all fees are 0 for now.
|
||||
active: true,
|
||||
};
|
||||
|
||||
pool_post.data = Data::from(&pool_post_definition);
|
||||
let pool_post: AccountPostState = if pool.account == Account::default() {
|
||||
AccountPostState::new_claimed(pool_post.clone())
|
||||
} else {
|
||||
AccountPostState::new(pool_post.clone())
|
||||
};
|
||||
let pool_post = AccountPostState::new_claimed_if_default(pool_post);
|
||||
|
||||
let token_program_id = user_holding_a.account.program_owner;
|
||||
|
||||
@@ -120,24 +129,12 @@ pub fn new_definition(
|
||||
},
|
||||
);
|
||||
|
||||
// Chain call for liquidity token (TokenLP definition -> User LP Holding)
|
||||
let instruction = if pool.account == Account::default() {
|
||||
token_core::Instruction::NewFungibleDefinition {
|
||||
name: String::from("LP Token"),
|
||||
total_supply: initial_lp,
|
||||
}
|
||||
} else {
|
||||
token_core::Instruction::Mint {
|
||||
amount_to_mint: initial_lp,
|
||||
}
|
||||
};
|
||||
|
||||
let mut pool_lp_auth = pool_definition_lp.clone();
|
||||
pool_lp_auth.is_authorized = true;
|
||||
|
||||
let call_token_lp = ChainedCall::new(
|
||||
token_program_id,
|
||||
vec![pool_lp_auth.clone(), user_holding_lp.clone()],
|
||||
vec![pool_lp_auth, user_holding_lp.clone()],
|
||||
&instruction,
|
||||
)
|
||||
.with_pda_seeds(vec![compute_liquidity_token_pda_seed(pool.account_id)]);
|
||||
@@ -145,14 +142,14 @@ pub fn new_definition(
|
||||
let chained_calls = vec![call_token_lp, call_token_b, call_token_a];
|
||||
|
||||
let post_states = vec![
|
||||
pool_post.clone(),
|
||||
AccountPostState::new(vault_a.account.clone()),
|
||||
AccountPostState::new(vault_b.account.clone()),
|
||||
AccountPostState::new(pool_definition_lp.account.clone()),
|
||||
AccountPostState::new(user_holding_a.account.clone()),
|
||||
AccountPostState::new(user_holding_b.account.clone()),
|
||||
AccountPostState::new(user_holding_lp.account.clone()),
|
||||
pool_post,
|
||||
AccountPostState::new(vault_a.account),
|
||||
AccountPostState::new(vault_b.account),
|
||||
AccountPostState::new(pool_definition_lp.account),
|
||||
AccountPostState::new(user_holding_a.account),
|
||||
AccountPostState::new(user_holding_b.account),
|
||||
AccountPostState::new(user_holding_lp.account),
|
||||
];
|
||||
|
||||
(post_states.clone(), chained_calls)
|
||||
(post_states, chained_calls)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use nssa_core::{
|
||||
};
|
||||
|
||||
#[expect(clippy::too_many_arguments, reason = "TODO: Fix later")]
|
||||
#[must_use]
|
||||
pub fn remove_liquidity(
|
||||
pool: AccountWithMetadata,
|
||||
vault_a: AccountWithMetadata,
|
||||
@@ -101,13 +102,13 @@ pub fn remove_liquidity(
|
||||
let active: bool = pool_def_data.liquidity_pool_supply - delta_lp != 0;
|
||||
|
||||
// 5. Update pool account
|
||||
let mut pool_post = pool.account.clone();
|
||||
let mut pool_post = pool.account;
|
||||
let pool_post_definition = PoolDefinition {
|
||||
liquidity_pool_supply: pool_def_data.liquidity_pool_supply - delta_lp,
|
||||
reserve_a: pool_def_data.reserve_a - withdraw_amount_a,
|
||||
reserve_b: pool_def_data.reserve_b - withdraw_amount_b,
|
||||
active,
|
||||
..pool_def_data.clone()
|
||||
..pool_def_data
|
||||
};
|
||||
|
||||
pool_post.data = Data::from(&pool_post_definition);
|
||||
@@ -153,13 +154,13 @@ pub fn remove_liquidity(
|
||||
let chained_calls = vec![call_token_lp, call_token_b, call_token_a];
|
||||
|
||||
let post_states = vec![
|
||||
AccountPostState::new(pool_post.clone()),
|
||||
AccountPostState::new(vault_a.account.clone()),
|
||||
AccountPostState::new(vault_b.account.clone()),
|
||||
AccountPostState::new(pool_definition_lp.account.clone()),
|
||||
AccountPostState::new(user_holding_a.account.clone()),
|
||||
AccountPostState::new(user_holding_b.account.clone()),
|
||||
AccountPostState::new(user_holding_lp.account.clone()),
|
||||
AccountPostState::new(pool_post),
|
||||
AccountPostState::new(vault_a.account),
|
||||
AccountPostState::new(vault_b.account),
|
||||
AccountPostState::new(pool_definition_lp.account),
|
||||
AccountPostState::new(user_holding_a.account),
|
||||
AccountPostState::new(user_holding_b.account),
|
||||
AccountPostState::new(user_holding_lp.account),
|
||||
];
|
||||
|
||||
(post_states, chained_calls)
|
||||
|
||||
@@ -5,6 +5,7 @@ use nssa_core::{
|
||||
};
|
||||
|
||||
#[expect(clippy::too_many_arguments, reason = "TODO: Fix later")]
|
||||
#[must_use]
|
||||
pub fn swap(
|
||||
pool: AccountWithMetadata,
|
||||
vault_a: AccountWithMetadata,
|
||||
@@ -95,7 +96,7 @@ pub fn swap(
|
||||
};
|
||||
|
||||
// Update pool account
|
||||
let mut pool_post = pool.account.clone();
|
||||
let mut pool_post = pool.account;
|
||||
let pool_post_definition = PoolDefinition {
|
||||
reserve_a: pool_def_data.reserve_a + deposit_a - withdraw_a,
|
||||
reserve_b: pool_def_data.reserve_b + deposit_b - withdraw_b,
|
||||
@@ -105,11 +106,11 @@ pub fn swap(
|
||||
pool_post.data = Data::from(&pool_post_definition);
|
||||
|
||||
let post_states = vec![
|
||||
AccountPostState::new(pool_post.clone()),
|
||||
AccountPostState::new(vault_a.account.clone()),
|
||||
AccountPostState::new(vault_b.account.clone()),
|
||||
AccountPostState::new(user_holding_a.account.clone()),
|
||||
AccountPostState::new(user_holding_b.account.clone()),
|
||||
AccountPostState::new(pool_post),
|
||||
AccountPostState::new(vault_a.account),
|
||||
AccountPostState::new(vault_b.account),
|
||||
AccountPostState::new(user_holding_a.account),
|
||||
AccountPostState::new(user_holding_b.account),
|
||||
];
|
||||
|
||||
(post_states, chained_calls)
|
||||
@@ -151,7 +152,7 @@ fn swap_logic(
|
||||
},
|
||||
));
|
||||
|
||||
let mut vault_withdraw = vault_withdraw.clone();
|
||||
let mut vault_withdraw = vault_withdraw;
|
||||
vault_withdraw.is_authorized = true;
|
||||
|
||||
let pda_seed = compute_vault_pda_seed(
|
||||
|
||||
+95
-95
@@ -107,7 +107,7 @@ impl BalanceForTests {
|
||||
|
||||
fn lp_supply_init() -> u128 {
|
||||
// sqrt(vault_a_reserve_init * vault_b_reserve_init) = sqrt(1000 * 500) = 707
|
||||
(BalanceForTests::vault_a_reserve_init() * BalanceForTests::vault_b_reserve_init()).isqrt()
|
||||
(Self::vault_a_reserve_init() * Self::vault_b_reserve_init()).isqrt()
|
||||
}
|
||||
|
||||
fn vault_a_swap_test_1() -> u128 {
|
||||
@@ -365,7 +365,7 @@ impl IdForTests {
|
||||
}
|
||||
|
||||
fn token_lp_definition_id() -> AccountId {
|
||||
compute_liquidity_token_pda(AMM_PROGRAM_ID, IdForTests::pool_definition_id())
|
||||
compute_liquidity_token_pda(AMM_PROGRAM_ID, Self::pool_definition_id())
|
||||
}
|
||||
|
||||
fn user_token_a_id() -> AccountId {
|
||||
@@ -383,24 +383,24 @@ impl IdForTests {
|
||||
fn pool_definition_id() -> AccountId {
|
||||
compute_pool_pda(
|
||||
AMM_PROGRAM_ID,
|
||||
IdForTests::token_a_definition_id(),
|
||||
IdForTests::token_b_definition_id(),
|
||||
Self::token_a_definition_id(),
|
||||
Self::token_b_definition_id(),
|
||||
)
|
||||
}
|
||||
|
||||
fn vault_a_id() -> AccountId {
|
||||
compute_vault_pda(
|
||||
AMM_PROGRAM_ID,
|
||||
IdForTests::pool_definition_id(),
|
||||
IdForTests::token_a_definition_id(),
|
||||
Self::pool_definition_id(),
|
||||
Self::token_a_definition_id(),
|
||||
)
|
||||
}
|
||||
|
||||
fn vault_b_id() -> AccountId {
|
||||
compute_vault_pda(
|
||||
AMM_PROGRAM_ID,
|
||||
IdForTests::pool_definition_id(),
|
||||
IdForTests::token_b_definition_id(),
|
||||
Self::pool_definition_id(),
|
||||
Self::token_b_definition_id(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -410,7 +410,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_a_definition_id(),
|
||||
balance: BalanceForTests::user_token_a_balance(),
|
||||
@@ -426,7 +426,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_b_definition_id(),
|
||||
balance: BalanceForTests::user_token_b_balance(),
|
||||
@@ -442,7 +442,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_a_definition_id(),
|
||||
balance: BalanceForTests::vault_a_reserve_init(),
|
||||
@@ -458,7 +458,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_b_definition_id(),
|
||||
balance: BalanceForTests::vault_b_reserve_init(),
|
||||
@@ -474,7 +474,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_a_definition_id(),
|
||||
balance: BalanceForTests::vault_a_reserve_high(),
|
||||
@@ -490,7 +490,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_b_definition_id(),
|
||||
balance: BalanceForTests::vault_b_reserve_high(),
|
||||
@@ -506,7 +506,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_a_definition_id(),
|
||||
balance: BalanceForTests::vault_a_reserve_low(),
|
||||
@@ -522,7 +522,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_b_definition_id(),
|
||||
balance: BalanceForTests::vault_b_reserve_low(),
|
||||
@@ -538,7 +538,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_a_definition_id(),
|
||||
balance: 0,
|
||||
@@ -554,7 +554,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_b_definition_id(),
|
||||
balance: 0,
|
||||
@@ -570,7 +570,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: BalanceForTests::lp_supply_init(),
|
||||
@@ -587,7 +587,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: BalanceForTests::lp_supply_init(),
|
||||
@@ -604,7 +604,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_lp_definition_id(),
|
||||
balance: 0,
|
||||
@@ -620,7 +620,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_lp_definition_id(),
|
||||
balance: BalanceForTests::user_token_lp_balance(),
|
||||
@@ -636,7 +636,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -646,7 +646,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::lp_supply_init(),
|
||||
reserve_a: BalanceForTests::vault_a_reserve_init(),
|
||||
reserve_b: BalanceForTests::vault_b_reserve_init(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -660,7 +660,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -670,7 +670,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::lp_supply_init(),
|
||||
reserve_a: 0,
|
||||
reserve_b: BalanceForTests::vault_b_reserve_init(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -684,7 +684,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -694,7 +694,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::lp_supply_init(),
|
||||
reserve_a: BalanceForTests::vault_a_reserve_init(),
|
||||
reserve_b: 0,
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -708,7 +708,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -718,7 +718,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::vault_a_reserve_low(),
|
||||
reserve_a: BalanceForTests::vault_a_reserve_low(),
|
||||
reserve_b: BalanceForTests::vault_b_reserve_high(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -732,7 +732,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -742,7 +742,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::vault_a_reserve_high(),
|
||||
reserve_a: BalanceForTests::vault_a_reserve_high(),
|
||||
reserve_b: BalanceForTests::vault_b_reserve_low(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -756,7 +756,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -766,7 +766,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::lp_supply_init(),
|
||||
reserve_a: BalanceForTests::vault_a_swap_test_1(),
|
||||
reserve_b: BalanceForTests::vault_b_swap_test_1(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -780,7 +780,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -790,7 +790,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::lp_supply_init(),
|
||||
reserve_a: BalanceForTests::vault_a_swap_test_2(),
|
||||
reserve_b: BalanceForTests::vault_b_swap_test_2(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -804,7 +804,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -814,7 +814,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::vault_a_reserve_low(),
|
||||
reserve_a: BalanceForTests::vault_a_reserve_init(),
|
||||
reserve_b: BalanceForTests::vault_b_reserve_init(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -828,7 +828,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -838,7 +838,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: 989,
|
||||
reserve_a: BalanceForTests::vault_a_add_successful(),
|
||||
reserve_b: BalanceForTests::vault_b_add_successful(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -852,7 +852,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -862,7 +862,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: 607,
|
||||
reserve_a: BalanceForTests::vault_a_remove_successful(),
|
||||
reserve_b: BalanceForTests::vault_b_remove_successful(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -876,7 +876,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -886,7 +886,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::lp_supply_init(),
|
||||
reserve_a: BalanceForTests::vault_a_reserve_init(),
|
||||
reserve_b: BalanceForTests::vault_b_reserve_init(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: false,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -900,7 +900,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -910,7 +910,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::lp_supply_init(),
|
||||
reserve_a: BalanceForTests::vault_a_reserve_init(),
|
||||
reserve_b: BalanceForTests::vault_b_reserve_init(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: false,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -924,7 +924,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_a_definition_id(),
|
||||
balance: BalanceForTests::vault_a_reserve_init(),
|
||||
@@ -940,7 +940,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: TOKEN_PROGRAM_ID,
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::token_b_definition_id(),
|
||||
balance: BalanceForTests::vault_b_reserve_init(),
|
||||
@@ -956,7 +956,7 @@ impl AccountForTests {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: ProgramId::default(),
|
||||
balance: 0u128,
|
||||
balance: 0_u128,
|
||||
data: Data::from(&PoolDefinition {
|
||||
definition_token_a_id: IdForTests::token_a_definition_id(),
|
||||
definition_token_b_id: IdForTests::token_b_definition_id(),
|
||||
@@ -966,7 +966,7 @@ impl AccountForTests {
|
||||
liquidity_pool_supply: BalanceForTests::lp_supply_init(),
|
||||
reserve_a: BalanceForTests::vault_a_reserve_init(),
|
||||
reserve_b: BalanceForTests::vault_b_reserve_init(),
|
||||
fees: 0u128,
|
||||
fees: 0_u128,
|
||||
active: true,
|
||||
}),
|
||||
nonce: 0u128.into(),
|
||||
@@ -978,7 +978,7 @@ impl AccountForTests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pool_pda_produces_unique_id_for_token_pair() {
|
||||
fn pool_pda_produces_unique_id_for_token_pair() {
|
||||
assert!(
|
||||
amm_core::compute_pool_pda(
|
||||
AMM_PROGRAM_ID,
|
||||
@@ -994,7 +994,7 @@ fn test_pool_pda_produces_unique_id_for_token_pair() {
|
||||
|
||||
#[should_panic(expected = "Vault A was not provided")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_vault_a_omitted() {
|
||||
fn call_add_liquidity_vault_a_omitted() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_with_wrong_id(),
|
||||
@@ -1011,7 +1011,7 @@ fn test_call_add_liquidity_vault_a_omitted() {
|
||||
|
||||
#[should_panic(expected = "Vault B was not provided")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_vault_b_omitted() {
|
||||
fn call_add_liquidity_vault_b_omitted() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1028,7 +1028,7 @@ fn test_call_add_liquidity_vault_b_omitted() {
|
||||
|
||||
#[should_panic(expected = "LP definition mismatch")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_lp_definition_mismatch() {
|
||||
fn call_add_liquidity_lp_definition_mismatch() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1045,7 +1045,7 @@ fn test_call_add_liquidity_lp_definition_mismatch() {
|
||||
|
||||
#[should_panic(expected = "Both max-balances must be nonzero")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_zero_balance_1() {
|
||||
fn call_add_liquidity_zero_balance_1() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1062,7 +1062,7 @@ fn test_call_add_liquidity_zero_balance_1() {
|
||||
|
||||
#[should_panic(expected = "Both max-balances must be nonzero")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_zero_balance_2() {
|
||||
fn call_add_liquidity_zero_balance_2() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1079,7 +1079,7 @@ fn test_call_add_liquidity_zero_balance_2() {
|
||||
|
||||
#[should_panic(expected = "Vaults' balances must be at least the reserve amounts")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_vault_insufficient_balance_1() {
|
||||
fn call_add_liquidity_vault_insufficient_balance_1() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init_zero(),
|
||||
@@ -1096,7 +1096,7 @@ fn test_call_add_liquidity_vault_insufficient_balance_1() {
|
||||
|
||||
#[should_panic(expected = "Vaults' balances must be at least the reserve amounts")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_vault_insufficient_balance_2() {
|
||||
fn call_add_liquidity_vault_insufficient_balance_2() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1113,7 +1113,7 @@ fn test_call_add_liquidity_vault_insufficient_balance_2() {
|
||||
|
||||
#[should_panic(expected = "A trade amount is 0")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_actual_amount_zero_1() {
|
||||
fn call_add_liquidity_actual_amount_zero_1() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init_reserve_a_low(),
|
||||
AccountForTests::vault_a_init_low(),
|
||||
@@ -1130,7 +1130,7 @@ fn test_call_add_liquidity_actual_amount_zero_1() {
|
||||
|
||||
#[should_panic(expected = "A trade amount is 0")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_actual_amount_zero_2() {
|
||||
fn call_add_liquidity_actual_amount_zero_2() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init_reserve_b_low(),
|
||||
AccountForTests::vault_a_init_high(),
|
||||
@@ -1147,7 +1147,7 @@ fn test_call_add_liquidity_actual_amount_zero_2() {
|
||||
|
||||
#[should_panic(expected = "Reserves must be nonzero")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_reserves_zero_1() {
|
||||
fn call_add_liquidity_reserves_zero_1() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init_reserve_a_zero(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1164,7 +1164,7 @@ fn test_call_add_liquidity_reserves_zero_1() {
|
||||
|
||||
#[should_panic(expected = "Reserves must be nonzero")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_reserves_zero_2() {
|
||||
fn call_add_liquidity_reserves_zero_2() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_init_reserve_b_zero(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1181,7 +1181,7 @@ fn test_call_add_liquidity_reserves_zero_2() {
|
||||
|
||||
#[should_panic(expected = "Payable LP must be nonzero")]
|
||||
#[test]
|
||||
fn test_call_add_liquidity_payable_lp_zero() {
|
||||
fn call_add_liquidity_payable_lp_zero() {
|
||||
let _post_states = add_liquidity(
|
||||
AccountForTests::pool_definition_add_zero_lp(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1197,7 +1197,7 @@ fn test_call_add_liquidity_payable_lp_zero() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_call_add_liquidity_chained_call_successsful() {
|
||||
fn call_add_liquidity_chained_call_successsful() {
|
||||
let (post_states, chained_calls) = add_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1226,7 +1226,7 @@ fn test_call_add_liquidity_chained_call_successsful() {
|
||||
|
||||
#[should_panic(expected = "Vault A was not provided")]
|
||||
#[test]
|
||||
fn test_call_remove_liquidity_vault_a_omitted() {
|
||||
fn call_remove_liquidity_vault_a_omitted() {
|
||||
let _post_states = remove_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_with_wrong_id(),
|
||||
@@ -1243,7 +1243,7 @@ fn test_call_remove_liquidity_vault_a_omitted() {
|
||||
|
||||
#[should_panic(expected = "Vault B was not provided")]
|
||||
#[test]
|
||||
fn test_call_remove_liquidity_vault_b_omitted() {
|
||||
fn call_remove_liquidity_vault_b_omitted() {
|
||||
let _post_states = remove_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1260,7 +1260,7 @@ fn test_call_remove_liquidity_vault_b_omitted() {
|
||||
|
||||
#[should_panic(expected = "LP definition mismatch")]
|
||||
#[test]
|
||||
fn test_call_remove_liquidity_lp_def_mismatch() {
|
||||
fn call_remove_liquidity_lp_def_mismatch() {
|
||||
let _post_states = remove_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1277,7 +1277,7 @@ fn test_call_remove_liquidity_lp_def_mismatch() {
|
||||
|
||||
#[should_panic(expected = "Invalid liquidity account provided")]
|
||||
#[test]
|
||||
fn test_call_remove_liquidity_insufficient_liquidity_amount() {
|
||||
fn call_remove_liquidity_insufficient_liquidity_amount() {
|
||||
let _post_states = remove_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1297,7 +1297,7 @@ fn test_call_remove_liquidity_insufficient_liquidity_amount() {
|
||||
expected = "Insufficient minimal withdraw amount (Token A) provided for liquidity amount"
|
||||
)]
|
||||
#[test]
|
||||
fn test_call_remove_liquidity_insufficient_balance_1() {
|
||||
fn call_remove_liquidity_insufficient_balance_1() {
|
||||
let _post_states = remove_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1316,7 +1316,7 @@ fn test_call_remove_liquidity_insufficient_balance_1() {
|
||||
expected = "Insufficient minimal withdraw amount (Token B) provided for liquidity amount"
|
||||
)]
|
||||
#[test]
|
||||
fn test_call_remove_liquidity_insufficient_balance_2() {
|
||||
fn call_remove_liquidity_insufficient_balance_2() {
|
||||
let _post_states = remove_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1333,7 +1333,7 @@ fn test_call_remove_liquidity_insufficient_balance_2() {
|
||||
|
||||
#[should_panic(expected = "Minimum withdraw amount must be nonzero")]
|
||||
#[test]
|
||||
fn test_call_remove_liquidity_min_bal_zero_1() {
|
||||
fn call_remove_liquidity_min_bal_zero_1() {
|
||||
let _post_states = remove_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1350,7 +1350,7 @@ fn test_call_remove_liquidity_min_bal_zero_1() {
|
||||
|
||||
#[should_panic(expected = "Minimum withdraw amount must be nonzero")]
|
||||
#[test]
|
||||
fn test_call_remove_liquidity_min_bal_zero_2() {
|
||||
fn call_remove_liquidity_min_bal_zero_2() {
|
||||
let _post_states = remove_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1366,7 +1366,7 @@ fn test_call_remove_liquidity_min_bal_zero_2() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_call_remove_liquidity_chained_call_successful() {
|
||||
fn call_remove_liquidity_chained_call_successful() {
|
||||
let (post_states, chained_calls) = remove_liquidity(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1395,7 +1395,7 @@ fn test_call_remove_liquidity_chained_call_successful() {
|
||||
|
||||
#[should_panic(expected = "Balances must be nonzero")]
|
||||
#[test]
|
||||
fn test_call_new_definition_with_zero_balance_1() {
|
||||
fn call_new_definition_with_zero_balance_1() {
|
||||
let _post_states = new_definition(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1412,7 +1412,7 @@ fn test_call_new_definition_with_zero_balance_1() {
|
||||
|
||||
#[should_panic(expected = "Balances must be nonzero")]
|
||||
#[test]
|
||||
fn test_call_new_definition_with_zero_balance_2() {
|
||||
fn call_new_definition_with_zero_balance_2() {
|
||||
let _post_states = new_definition(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1429,7 +1429,7 @@ fn test_call_new_definition_with_zero_balance_2() {
|
||||
|
||||
#[should_panic(expected = "Cannot set up a swap for a token with itself")]
|
||||
#[test]
|
||||
fn test_call_new_definition_same_token_definition() {
|
||||
fn call_new_definition_same_token_definition() {
|
||||
let _post_states = new_definition(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1446,7 +1446,7 @@ fn test_call_new_definition_same_token_definition() {
|
||||
|
||||
#[should_panic(expected = "Liquidity pool Token Definition Account ID does not match PDA")]
|
||||
#[test]
|
||||
fn test_call_new_definition_wrong_liquidity_id() {
|
||||
fn call_new_definition_wrong_liquidity_id() {
|
||||
let _post_states = new_definition(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1463,7 +1463,7 @@ fn test_call_new_definition_wrong_liquidity_id() {
|
||||
|
||||
#[should_panic(expected = "Pool Definition Account ID does not match PDA")]
|
||||
#[test]
|
||||
fn test_call_new_definition_wrong_pool_id() {
|
||||
fn call_new_definition_wrong_pool_id() {
|
||||
let _post_states = new_definition(
|
||||
AccountForTests::pool_definition_with_wrong_id(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1480,7 +1480,7 @@ fn test_call_new_definition_wrong_pool_id() {
|
||||
|
||||
#[should_panic(expected = "Vault ID does not match PDA")]
|
||||
#[test]
|
||||
fn test_call_new_definition_wrong_vault_id_1() {
|
||||
fn call_new_definition_wrong_vault_id_1() {
|
||||
let _post_states = new_definition(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_with_wrong_id(),
|
||||
@@ -1497,7 +1497,7 @@ fn test_call_new_definition_wrong_vault_id_1() {
|
||||
|
||||
#[should_panic(expected = "Vault ID does not match PDA")]
|
||||
#[test]
|
||||
fn test_call_new_definition_wrong_vault_id_2() {
|
||||
fn call_new_definition_wrong_vault_id_2() {
|
||||
let _post_states = new_definition(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1514,7 +1514,7 @@ fn test_call_new_definition_wrong_vault_id_2() {
|
||||
|
||||
#[should_panic(expected = "Cannot initialize an active Pool Definition")]
|
||||
#[test]
|
||||
fn test_call_new_definition_cannot_initialize_active_pool() {
|
||||
fn call_new_definition_cannot_initialize_active_pool() {
|
||||
let _post_states = new_definition(
|
||||
AccountForTests::pool_definition_active(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1531,7 +1531,7 @@ fn test_call_new_definition_cannot_initialize_active_pool() {
|
||||
|
||||
#[should_panic(expected = "Cannot initialize an active Pool Definition")]
|
||||
#[test]
|
||||
fn test_call_new_definition_chained_call_successful() {
|
||||
fn call_new_definition_chained_call_successful() {
|
||||
let (post_states, chained_calls) = new_definition(
|
||||
AccountForTests::pool_definition_active(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1560,7 +1560,7 @@ fn test_call_new_definition_chained_call_successful() {
|
||||
|
||||
#[should_panic(expected = "AccountId is not a token type for the pool")]
|
||||
#[test]
|
||||
fn test_call_swap_incorrect_token_type() {
|
||||
fn call_swap_incorrect_token_type() {
|
||||
let _post_states = swap(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1575,7 +1575,7 @@ fn test_call_swap_incorrect_token_type() {
|
||||
|
||||
#[should_panic(expected = "Vault A was not provided")]
|
||||
#[test]
|
||||
fn test_call_swap_vault_a_omitted() {
|
||||
fn call_swap_vault_a_omitted() {
|
||||
let _post_states = swap(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_with_wrong_id(),
|
||||
@@ -1590,7 +1590,7 @@ fn test_call_swap_vault_a_omitted() {
|
||||
|
||||
#[should_panic(expected = "Vault B was not provided")]
|
||||
#[test]
|
||||
fn test_call_swap_vault_b_omitted() {
|
||||
fn call_swap_vault_b_omitted() {
|
||||
let _post_states = swap(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1605,7 +1605,7 @@ fn test_call_swap_vault_b_omitted() {
|
||||
|
||||
#[should_panic(expected = "Reserve for Token A exceeds vault balance")]
|
||||
#[test]
|
||||
fn test_call_swap_reserves_vault_mismatch_1() {
|
||||
fn call_swap_reserves_vault_mismatch_1() {
|
||||
let _post_states = swap(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init_low(),
|
||||
@@ -1620,7 +1620,7 @@ fn test_call_swap_reserves_vault_mismatch_1() {
|
||||
|
||||
#[should_panic(expected = "Reserve for Token B exceeds vault balance")]
|
||||
#[test]
|
||||
fn test_call_swap_reserves_vault_mismatch_2() {
|
||||
fn call_swap_reserves_vault_mismatch_2() {
|
||||
let _post_states = swap(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1635,7 +1635,7 @@ fn test_call_swap_reserves_vault_mismatch_2() {
|
||||
|
||||
#[should_panic(expected = "Pool is inactive")]
|
||||
#[test]
|
||||
fn test_call_swap_ianctive() {
|
||||
fn call_swap_ianctive() {
|
||||
let _post_states = swap(
|
||||
AccountForTests::pool_definition_inactive(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1650,7 +1650,7 @@ fn test_call_swap_ianctive() {
|
||||
|
||||
#[should_panic(expected = "Withdraw amount is less than minimal amount out")]
|
||||
#[test]
|
||||
fn test_call_swap_below_min_out() {
|
||||
fn call_swap_below_min_out() {
|
||||
let _post_states = swap(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1664,7 +1664,7 @@ fn test_call_swap_below_min_out() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_call_swap_chained_call_successful_1() {
|
||||
fn call_swap_chained_call_successful_1() {
|
||||
let (post_states, chained_calls) = swap(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1694,7 +1694,7 @@ fn test_call_swap_chained_call_successful_1() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_call_swap_chained_call_successful_2() {
|
||||
fn call_swap_chained_call_successful_2() {
|
||||
let (post_states, chained_calls) = swap(
|
||||
AccountForTests::pool_definition_init(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1724,7 +1724,7 @@ fn test_call_swap_chained_call_successful_2() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_definition_lp_asymmetric_amounts() {
|
||||
fn new_definition_lp_asymmetric_amounts() {
|
||||
let (post_states, chained_calls) = new_definition(
|
||||
AccountForTests::pool_definition_inactive(),
|
||||
AccountForTests::vault_a_init(),
|
||||
@@ -1751,10 +1751,10 @@ fn test_new_definition_lp_asymmetric_amounts() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_definition_lp_symmetric_amounts() {
|
||||
fn new_definition_lp_symmetric_amounts() {
|
||||
// token_a=100, token_b=100 → LP=sqrt(10_000)=100
|
||||
let token_a_amount = 100u128;
|
||||
let token_b_amount = 100u128;
|
||||
let token_a_amount = 100_u128;
|
||||
let token_b_amount = 100_u128;
|
||||
let expected_lp = (token_a_amount * token_b_amount).isqrt();
|
||||
assert_eq!(expected_lp, 100);
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
nssa_core.workspace = true
|
||||
token_core.workspace = true
|
||||
|
||||
@@ -4,6 +4,9 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
nssa_core.workspace = true
|
||||
serde.workspace = true
|
||||
|
||||
@@ -29,7 +29,7 @@ pub enum Instruction {
|
||||
/// - Token Metadata account (uninitialized).
|
||||
NewDefinitionWithMetadata {
|
||||
new_definition: NewTokenDefinition,
|
||||
/// Boxed to avoid large enum variant size
|
||||
/// Boxed to avoid large enum variant size.
|
||||
metadata: Box<NewTokenMetadata>,
|
||||
},
|
||||
|
||||
@@ -92,7 +92,7 @@ impl TryFrom<&Data> for TokenDefinition {
|
||||
type Error = std::io::Error;
|
||||
|
||||
fn try_from(data: &Data) -> Result<Self, Self::Error> {
|
||||
TokenDefinition::try_from_slice(data.as_ref())
|
||||
Self::try_from_slice(data.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ impl From<&TokenDefinition> for Data {
|
||||
BorshSerialize::serialize(definition, &mut data)
|
||||
.expect("Serialization to Vec should not fail");
|
||||
|
||||
Data::try_from(data).expect("Token definition encoded data should fit into Data")
|
||||
Self::try_from(data).expect("Token definition encoded data should fit into Data")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,44 +127,47 @@ pub enum TokenHolding {
|
||||
}
|
||||
|
||||
impl TokenHolding {
|
||||
pub fn zeroized_clone_from(other: &Self) -> Self {
|
||||
#[must_use]
|
||||
pub const fn zeroized_clone_from(other: &Self) -> Self {
|
||||
match other {
|
||||
TokenHolding::Fungible { definition_id, .. } => TokenHolding::Fungible {
|
||||
Self::Fungible { definition_id, .. } => Self::Fungible {
|
||||
definition_id: *definition_id,
|
||||
balance: 0,
|
||||
},
|
||||
TokenHolding::NftMaster { definition_id, .. } => TokenHolding::NftMaster {
|
||||
Self::NftMaster { definition_id, .. } => Self::NftMaster {
|
||||
definition_id: *definition_id,
|
||||
print_balance: 0,
|
||||
},
|
||||
TokenHolding::NftPrintedCopy { definition_id, .. } => TokenHolding::NftPrintedCopy {
|
||||
Self::NftPrintedCopy { definition_id, .. } => Self::NftPrintedCopy {
|
||||
definition_id: *definition_id,
|
||||
owned: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn zeroized_from_definition(
|
||||
#[must_use]
|
||||
pub const fn zeroized_from_definition(
|
||||
definition_id: AccountId,
|
||||
definition: &TokenDefinition,
|
||||
) -> Self {
|
||||
match definition {
|
||||
TokenDefinition::Fungible { .. } => TokenHolding::Fungible {
|
||||
TokenDefinition::Fungible { .. } => Self::Fungible {
|
||||
definition_id,
|
||||
balance: 0,
|
||||
},
|
||||
TokenDefinition::NonFungible { .. } => TokenHolding::NftPrintedCopy {
|
||||
TokenDefinition::NonFungible { .. } => Self::NftPrintedCopy {
|
||||
definition_id,
|
||||
owned: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn definition_id(&self) -> AccountId {
|
||||
#[must_use]
|
||||
pub const fn definition_id(&self) -> AccountId {
|
||||
match self {
|
||||
TokenHolding::Fungible { definition_id, .. } => *definition_id,
|
||||
TokenHolding::NftMaster { definition_id, .. } => *definition_id,
|
||||
TokenHolding::NftPrintedCopy { definition_id, .. } => *definition_id,
|
||||
Self::Fungible { definition_id, .. }
|
||||
| Self::NftMaster { definition_id, .. }
|
||||
| Self::NftPrintedCopy { definition_id, .. } => *definition_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,7 +176,7 @@ impl TryFrom<&Data> for TokenHolding {
|
||||
type Error = std::io::Error;
|
||||
|
||||
fn try_from(data: &Data) -> Result<Self, Self::Error> {
|
||||
TokenHolding::try_from_slice(data.as_ref())
|
||||
Self::try_from_slice(data.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +188,7 @@ impl From<&TokenHolding> for Data {
|
||||
BorshSerialize::serialize(holding, &mut data)
|
||||
.expect("Serialization to Vec should not fail");
|
||||
|
||||
Data::try_from(data).expect("Token holding encoded data should fit into Data")
|
||||
Self::try_from(data).expect("Token holding encoded data should fit into Data")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +196,7 @@ impl From<&TokenHolding> for Data {
|
||||
pub struct NewTokenMetadata {
|
||||
/// Metadata standard.
|
||||
pub standard: MetadataStandard,
|
||||
/// Pointer to off-chain metadata
|
||||
/// Pointer to off-chain metadata.
|
||||
pub uri: String,
|
||||
/// Creators of the token.
|
||||
pub creators: String,
|
||||
@@ -224,7 +227,7 @@ impl TryFrom<&Data> for TokenMetadata {
|
||||
type Error = std::io::Error;
|
||||
|
||||
fn try_from(data: &Data) -> Result<Self, Self::Error> {
|
||||
TokenMetadata::try_from_slice(data.as_ref())
|
||||
Self::try_from_slice(data.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,6 +239,6 @@ impl From<&TokenMetadata> for Data {
|
||||
BorshSerialize::serialize(metadata, &mut data)
|
||||
.expect("Serialization to Vec should not fail");
|
||||
|
||||
Data::try_from(data).expect("Token metadata encoded data should fit into Data")
|
||||
Self::try_from(data).expect("Token metadata encoded data should fit into Data")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use nssa_core::{
|
||||
};
|
||||
use token_core::{TokenDefinition, TokenHolding};
|
||||
|
||||
#[must_use]
|
||||
pub fn burn(
|
||||
definition_account: AccountWithMetadata,
|
||||
user_holding_account: AccountWithMetadata,
|
||||
|
||||
@@ -4,6 +4,7 @@ use nssa_core::{
|
||||
};
|
||||
use token_core::{TokenDefinition, TokenHolding};
|
||||
|
||||
#[must_use]
|
||||
pub fn initialize_account(
|
||||
definition_account: AccountWithMetadata,
|
||||
account_to_initialize: AccountWithMetadata,
|
||||
|
||||
@@ -4,6 +4,7 @@ use nssa_core::{
|
||||
};
|
||||
use token_core::{TokenDefinition, TokenHolding};
|
||||
|
||||
#[must_use]
|
||||
pub fn mint(
|
||||
definition_account: AccountWithMetadata,
|
||||
user_holding_account: AccountWithMetadata,
|
||||
|
||||
@@ -6,6 +6,7 @@ use token_core::{
|
||||
NewTokenDefinition, NewTokenMetadata, TokenDefinition, TokenHolding, TokenMetadata,
|
||||
};
|
||||
|
||||
#[must_use]
|
||||
pub fn new_fungible_definition(
|
||||
definition_target_account: AccountWithMetadata,
|
||||
holding_target_account: AccountWithMetadata,
|
||||
@@ -46,6 +47,7 @@ pub fn new_fungible_definition(
|
||||
]
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new_definition_with_metadata(
|
||||
definition_target_account: AccountWithMetadata,
|
||||
holding_target_account: AccountWithMetadata,
|
||||
@@ -104,16 +106,16 @@ pub fn new_definition_with_metadata(
|
||||
standard: metadata.standard,
|
||||
uri: metadata.uri,
|
||||
creators: metadata.creators,
|
||||
primary_sale_date: 0u64, // TODO #261: future works to implement this
|
||||
primary_sale_date: 0_u64, // TODO #261: future works to implement this
|
||||
};
|
||||
|
||||
let mut definition_target_account_post = definition_target_account.account.clone();
|
||||
let mut definition_target_account_post = definition_target_account.account;
|
||||
definition_target_account_post.data = Data::from(&token_definition);
|
||||
|
||||
let mut holding_target_account_post = holding_target_account.account.clone();
|
||||
let mut holding_target_account_post = holding_target_account.account;
|
||||
holding_target_account_post.data = Data::from(&token_holding);
|
||||
|
||||
let mut metadata_target_account_post = metadata_target_account.account.clone();
|
||||
let mut metadata_target_account_post = metadata_target_account.account;
|
||||
metadata_target_account_post.data = Data::from(&token_metadata);
|
||||
|
||||
vec![
|
||||
|
||||
@@ -4,6 +4,7 @@ use nssa_core::{
|
||||
};
|
||||
use token_core::TokenHolding;
|
||||
|
||||
#[must_use]
|
||||
pub fn print_nft(
|
||||
master_account: AccountWithMetadata,
|
||||
printed_account: AccountWithMetadata,
|
||||
@@ -36,7 +37,7 @@ pub fn print_nft(
|
||||
*print_balance > 1,
|
||||
"Insufficient balance to print another NFT copy"
|
||||
);
|
||||
*print_balance -= 1;
|
||||
*print_balance = print_balance.checked_sub(1).expect("Checked above");
|
||||
|
||||
let mut master_account_post = master_account.account;
|
||||
master_account_post.data = Data::from(&master_account_data);
|
||||
|
||||
+98
-93
@@ -1,4 +1,9 @@
|
||||
#![cfg(test)]
|
||||
#![expect(
|
||||
clippy::shadow_unrelated,
|
||||
clippy::arithmetic_side_effects,
|
||||
reason = "We don't care about it in tests"
|
||||
)]
|
||||
|
||||
use nssa_core::account::{Account, AccountId, AccountWithMetadata, Data};
|
||||
use token_core::{
|
||||
@@ -25,8 +30,8 @@ impl AccountForTests {
|
||||
fn definition_account_auth() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: BalanceForTests::init_supply(),
|
||||
@@ -42,8 +47,8 @@ impl AccountForTests {
|
||||
fn definition_account_without_auth() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: BalanceForTests::init_supply(),
|
||||
@@ -59,8 +64,8 @@ impl AccountForTests {
|
||||
fn holding_different_definition() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id_diff(),
|
||||
balance: BalanceForTests::holding_balance(),
|
||||
@@ -75,8 +80,8 @@ impl AccountForTests {
|
||||
fn holding_same_definition_with_authorization() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::holding_balance(),
|
||||
@@ -91,8 +96,8 @@ impl AccountForTests {
|
||||
fn holding_same_definition_without_authorization() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::holding_balance(),
|
||||
@@ -107,8 +112,8 @@ impl AccountForTests {
|
||||
fn holding_same_definition_without_authorization_overflow() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::init_supply(),
|
||||
@@ -123,8 +128,8 @@ impl AccountForTests {
|
||||
fn definition_account_post_burn() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: BalanceForTests::init_supply_burned(),
|
||||
@@ -140,8 +145,8 @@ impl AccountForTests {
|
||||
fn holding_account_post_burn() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::holding_balance_burned(),
|
||||
@@ -164,8 +169,8 @@ impl AccountForTests {
|
||||
fn init_mint() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [0u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [0_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::mint_success(),
|
||||
@@ -180,8 +185,8 @@ impl AccountForTests {
|
||||
fn holding_account_same_definition_mint() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::holding_balance_mint(),
|
||||
@@ -196,8 +201,8 @@ impl AccountForTests {
|
||||
fn definition_account_mint() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: BalanceForTests::init_supply_mint(),
|
||||
@@ -213,8 +218,8 @@ impl AccountForTests {
|
||||
fn holding_same_definition_with_authorization_and_large_balance() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::mint_overflow(),
|
||||
@@ -229,8 +234,8 @@ impl AccountForTests {
|
||||
fn definition_account_with_authorization_nonfungible() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenDefinition::NonFungible {
|
||||
name: String::from("test"),
|
||||
printable_supply: BalanceForTests::printable_copies(),
|
||||
@@ -254,8 +259,8 @@ impl AccountForTests {
|
||||
fn holding_account_init() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::init_supply(),
|
||||
@@ -270,8 +275,8 @@ impl AccountForTests {
|
||||
fn definition_account_unclaimed() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [0u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [0_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: BalanceForTests::init_supply(),
|
||||
@@ -287,8 +292,8 @@ impl AccountForTests {
|
||||
fn holding_account_unclaimed() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [0u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [0_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::init_supply(),
|
||||
@@ -303,8 +308,8 @@ impl AccountForTests {
|
||||
fn holding_account2_init() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::init_supply(),
|
||||
@@ -319,8 +324,8 @@ impl AccountForTests {
|
||||
fn holding_account2_init_post_transfer() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::recipient_post_transfer(),
|
||||
@@ -335,8 +340,8 @@ impl AccountForTests {
|
||||
fn holding_account_init_post_transfer() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::Fungible {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
balance: BalanceForTests::sender_post_transfer(),
|
||||
@@ -351,8 +356,8 @@ impl AccountForTests {
|
||||
fn holding_account_master_nft() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::NftMaster {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
print_balance: BalanceForTests::printable_copies(),
|
||||
@@ -367,8 +372,8 @@ impl AccountForTests {
|
||||
fn holding_account_master_nft_insufficient_balance() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::NftMaster {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
print_balance: 1,
|
||||
@@ -383,8 +388,8 @@ impl AccountForTests {
|
||||
fn holding_account_master_nft_after_print() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::NftMaster {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
print_balance: BalanceForTests::printable_copies() - 1,
|
||||
@@ -399,8 +404,8 @@ impl AccountForTests {
|
||||
fn holding_account_printed_nft() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [0u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [0_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::NftPrintedCopy {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
owned: true,
|
||||
@@ -415,8 +420,8 @@ impl AccountForTests {
|
||||
fn holding_account_with_master_nft_transferred_to() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [0u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [0_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::NftMaster {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
print_balance: BalanceForTests::printable_copies(),
|
||||
@@ -431,8 +436,8 @@ impl AccountForTests {
|
||||
fn holding_account_master_nft_post_transfer() -> AccountWithMetadata {
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [5u32; 8],
|
||||
balance: 0u128,
|
||||
program_owner: [5_u32; 8],
|
||||
balance: 0_u128,
|
||||
data: Data::from(&TokenHolding::NftMaster {
|
||||
definition_id: IdForTests::pool_definition_id(),
|
||||
print_balance: 0,
|
||||
@@ -523,7 +528,7 @@ impl IdForTests {
|
||||
|
||||
#[should_panic(expected = "Definition target account must have default values")]
|
||||
#[test]
|
||||
fn test_new_definition_non_default_first_account_should_fail() {
|
||||
fn new_definition_non_default_first_account_should_fail() {
|
||||
let definition_account = AccountWithMetadata {
|
||||
account: Account {
|
||||
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
|
||||
@@ -547,7 +552,7 @@ fn test_new_definition_non_default_first_account_should_fail() {
|
||||
|
||||
#[should_panic(expected = "Holding target account must have default values")]
|
||||
#[test]
|
||||
fn test_new_definition_non_default_second_account_should_fail() {
|
||||
fn new_definition_non_default_second_account_should_fail() {
|
||||
let definition_account = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: true,
|
||||
@@ -570,7 +575,7 @@ fn test_new_definition_non_default_second_account_should_fail() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_definition_with_valid_inputs_succeeds() {
|
||||
fn new_definition_with_valid_inputs_succeeds() {
|
||||
let definition_account = AccountForTests::definition_account_uninit();
|
||||
let holding_account = AccountForTests::holding_account_uninit();
|
||||
|
||||
@@ -595,7 +600,7 @@ fn test_new_definition_with_valid_inputs_succeeds() {
|
||||
|
||||
#[should_panic(expected = "Sender and recipient definition id mismatch")]
|
||||
#[test]
|
||||
fn test_transfer_with_different_definition_ids_should_fail() {
|
||||
fn transfer_with_different_definition_ids_should_fail() {
|
||||
let sender = AccountForTests::holding_same_definition_with_authorization();
|
||||
let recipient = AccountForTests::holding_different_definition();
|
||||
let _post_states = transfer(sender, recipient, 10);
|
||||
@@ -603,7 +608,7 @@ fn test_transfer_with_different_definition_ids_should_fail() {
|
||||
|
||||
#[should_panic(expected = "Insufficient balance")]
|
||||
#[test]
|
||||
fn test_transfer_with_insufficient_balance_should_fail() {
|
||||
fn transfer_with_insufficient_balance_should_fail() {
|
||||
let sender = AccountForTests::holding_same_definition_with_authorization();
|
||||
let recipient = AccountForTests::holding_account_same_definition_mint();
|
||||
// Attempt to transfer more than balance
|
||||
@@ -612,14 +617,14 @@ fn test_transfer_with_insufficient_balance_should_fail() {
|
||||
|
||||
#[should_panic(expected = "Sender authorization is missing")]
|
||||
#[test]
|
||||
fn test_transfer_without_sender_authorization_should_fail() {
|
||||
fn transfer_without_sender_authorization_should_fail() {
|
||||
let sender = AccountForTests::holding_same_definition_without_authorization();
|
||||
let recipient = AccountForTests::holding_account_uninit();
|
||||
let _post_states = transfer(sender, recipient, 37);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transfer_with_valid_inputs_succeeds() {
|
||||
fn transfer_with_valid_inputs_succeeds() {
|
||||
let sender = AccountForTests::holding_account_init();
|
||||
let recipient = AccountForTests::holding_account2_init();
|
||||
let post_states = transfer(sender, recipient, BalanceForTests::transfer_amount());
|
||||
@@ -637,7 +642,7 @@ fn test_transfer_with_valid_inputs_succeeds() {
|
||||
|
||||
#[should_panic(expected = "Invalid balance for NFT Master transfer")]
|
||||
#[test]
|
||||
fn test_transfer_with_master_nft_invalid_balance() {
|
||||
fn transfer_with_master_nft_invalid_balance() {
|
||||
let sender = AccountForTests::holding_account_master_nft();
|
||||
let recipient = AccountForTests::holding_account_uninit();
|
||||
let _post_states = transfer(sender, recipient, BalanceForTests::transfer_amount());
|
||||
@@ -645,14 +650,14 @@ fn test_transfer_with_master_nft_invalid_balance() {
|
||||
|
||||
#[should_panic(expected = "Invalid balance in recipient account for NFT transfer")]
|
||||
#[test]
|
||||
fn test_transfer_with_master_nft_invalid_recipient_balance() {
|
||||
fn transfer_with_master_nft_invalid_recipient_balance() {
|
||||
let sender = AccountForTests::holding_account_master_nft();
|
||||
let recipient = AccountForTests::holding_account_with_master_nft_transferred_to();
|
||||
let _post_states = transfer(sender, recipient, BalanceForTests::printable_copies());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transfer_with_master_nft_success() {
|
||||
fn transfer_with_master_nft_success() {
|
||||
let sender = AccountForTests::holding_account_master_nft();
|
||||
let recipient = AccountForTests::holding_account_uninit();
|
||||
let post_states = transfer(sender, recipient, BalanceForTests::printable_copies());
|
||||
@@ -669,7 +674,7 @@ fn test_transfer_with_master_nft_success() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_token_initialize_account_succeeds() {
|
||||
fn token_initialize_account_succeeds() {
|
||||
let sender = AccountForTests::holding_account_init();
|
||||
let recipient = AccountForTests::holding_account2_init();
|
||||
let post_states = transfer(sender, recipient, BalanceForTests::transfer_amount());
|
||||
@@ -687,7 +692,7 @@ fn test_token_initialize_account_succeeds() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Mismatch Token Definition and Token Holding")]
|
||||
fn test_burn_mismatch_def() {
|
||||
fn burn_mismatch_def() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::holding_different_definition();
|
||||
let _post_states = burn(
|
||||
@@ -699,7 +704,7 @@ fn test_burn_mismatch_def() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Authorization is missing")]
|
||||
fn test_burn_missing_authorization() {
|
||||
fn burn_missing_authorization() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::holding_same_definition_without_authorization();
|
||||
let _post_states = burn(
|
||||
@@ -711,7 +716,7 @@ fn test_burn_missing_authorization() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Insufficient balance to burn")]
|
||||
fn test_burn_insufficient_balance() {
|
||||
fn burn_insufficient_balance() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::holding_same_definition_with_authorization();
|
||||
let _post_states = burn(
|
||||
@@ -723,7 +728,7 @@ fn test_burn_insufficient_balance() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Total supply underflow")]
|
||||
fn test_burn_total_supply_underflow() {
|
||||
fn burn_total_supply_underflow() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account =
|
||||
AccountForTests::holding_same_definition_with_authorization_and_large_balance();
|
||||
@@ -735,7 +740,7 @@ fn test_burn_total_supply_underflow() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_burn_success() {
|
||||
fn burn_success() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::holding_same_definition_with_authorization();
|
||||
let post_states = burn(
|
||||
@@ -758,7 +763,7 @@ fn test_burn_success() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Holding account must be valid")]
|
||||
fn test_mint_not_valid_holding_account() {
|
||||
fn mint_not_valid_holding_account() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::definition_account_without_auth();
|
||||
let _post_states = mint(
|
||||
@@ -770,7 +775,7 @@ fn test_mint_not_valid_holding_account() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Definition account must be valid")]
|
||||
fn test_mint_not_valid_definition_account() {
|
||||
fn mint_not_valid_definition_account() {
|
||||
let definition_account = AccountForTests::holding_same_definition_with_authorization();
|
||||
let holding_account = AccountForTests::holding_same_definition_without_authorization();
|
||||
let _post_states = mint(
|
||||
@@ -782,7 +787,7 @@ fn test_mint_not_valid_definition_account() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Definition authorization is missing")]
|
||||
fn test_mint_missing_authorization() {
|
||||
fn mint_missing_authorization() {
|
||||
let definition_account = AccountForTests::definition_account_without_auth();
|
||||
let holding_account = AccountForTests::holding_same_definition_without_authorization();
|
||||
let _post_states = mint(
|
||||
@@ -794,7 +799,7 @@ fn test_mint_missing_authorization() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Mismatch Token Definition and Token Holding")]
|
||||
fn test_mint_mismatched_token_definition() {
|
||||
fn mint_mismatched_token_definition() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::holding_different_definition();
|
||||
let _post_states = mint(
|
||||
@@ -805,7 +810,7 @@ fn test_mint_mismatched_token_definition() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mint_success() {
|
||||
fn mint_success() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::holding_same_definition_without_authorization();
|
||||
let post_states = mint(
|
||||
@@ -827,7 +832,7 @@ fn test_mint_success() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mint_uninit_holding_success() {
|
||||
fn mint_uninit_holding_success() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::holding_account_uninit();
|
||||
let post_states = mint(
|
||||
@@ -851,7 +856,7 @@ fn test_mint_uninit_holding_success() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Total supply overflow")]
|
||||
fn test_mint_total_supply_overflow() {
|
||||
fn mint_total_supply_overflow() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::holding_same_definition_without_authorization();
|
||||
let _post_states = mint(
|
||||
@@ -863,7 +868,7 @@ fn test_mint_total_supply_overflow() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Balance overflow on minting")]
|
||||
fn test_mint_holding_account_overflow() {
|
||||
fn mint_holding_account_overflow() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let holding_account = AccountForTests::holding_same_definition_without_authorization_overflow();
|
||||
let _post_states = mint(
|
||||
@@ -875,7 +880,7 @@ fn test_mint_holding_account_overflow() {
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Cannot mint additional supply for Non-Fungible Tokens")]
|
||||
fn test_mint_cannot_mint_unmintable_tokens() {
|
||||
fn mint_cannot_mint_unmintable_tokens() {
|
||||
let definition_account = AccountForTests::definition_account_with_authorization_nonfungible();
|
||||
let holding_account = AccountForTests::holding_account_master_nft();
|
||||
let _post_states = mint(
|
||||
@@ -887,7 +892,7 @@ fn test_mint_cannot_mint_unmintable_tokens() {
|
||||
|
||||
#[should_panic(expected = "Definition target account must have default values")]
|
||||
#[test]
|
||||
fn test_call_new_definition_metadata_with_init_definition() {
|
||||
fn call_new_definition_metadata_with_init_definition() {
|
||||
let definition_account = AccountForTests::definition_account_auth();
|
||||
let metadata_account = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
@@ -901,12 +906,12 @@ fn test_call_new_definition_metadata_with_init_definition() {
|
||||
};
|
||||
let new_definition = NewTokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: 15u128,
|
||||
total_supply: 15_u128,
|
||||
};
|
||||
let metadata = NewTokenMetadata {
|
||||
standard: MetadataStandard::Simple,
|
||||
uri: "test_uri".to_string(),
|
||||
creators: "test_creators".to_string(),
|
||||
uri: "test_uri".to_owned(),
|
||||
creators: "test_creators".to_owned(),
|
||||
};
|
||||
let _post_states = new_definition_with_metadata(
|
||||
definition_account,
|
||||
@@ -919,7 +924,7 @@ fn test_call_new_definition_metadata_with_init_definition() {
|
||||
|
||||
#[should_panic(expected = "Metadata target account must have default values")]
|
||||
#[test]
|
||||
fn test_call_new_definition_metadata_with_init_metadata() {
|
||||
fn call_new_definition_metadata_with_init_metadata() {
|
||||
let definition_account = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: true,
|
||||
@@ -933,12 +938,12 @@ fn test_call_new_definition_metadata_with_init_metadata() {
|
||||
let metadata_account = AccountForTests::holding_account_same_definition_mint();
|
||||
let new_definition = NewTokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: 15u128,
|
||||
total_supply: 15_u128,
|
||||
};
|
||||
let metadata = NewTokenMetadata {
|
||||
standard: MetadataStandard::Simple,
|
||||
uri: "test_uri".to_string(),
|
||||
creators: "test_creators".to_string(),
|
||||
uri: "test_uri".to_owned(),
|
||||
creators: "test_creators".to_owned(),
|
||||
};
|
||||
let _post_states = new_definition_with_metadata(
|
||||
definition_account,
|
||||
@@ -951,7 +956,7 @@ fn test_call_new_definition_metadata_with_init_metadata() {
|
||||
|
||||
#[should_panic(expected = "Holding target account must have default values")]
|
||||
#[test]
|
||||
fn test_call_new_definition_metadata_with_init_holding() {
|
||||
fn call_new_definition_metadata_with_init_holding() {
|
||||
let definition_account = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: true,
|
||||
@@ -965,12 +970,12 @@ fn test_call_new_definition_metadata_with_init_holding() {
|
||||
let holding_account = AccountForTests::holding_account_same_definition_mint();
|
||||
let new_definition = NewTokenDefinition::Fungible {
|
||||
name: String::from("test"),
|
||||
total_supply: 15u128,
|
||||
total_supply: 15_u128,
|
||||
};
|
||||
let metadata = NewTokenMetadata {
|
||||
standard: MetadataStandard::Simple,
|
||||
uri: "test_uri".to_string(),
|
||||
creators: "test_creators".to_string(),
|
||||
uri: "test_uri".to_owned(),
|
||||
creators: "test_creators".to_owned(),
|
||||
};
|
||||
let _post_states = new_definition_with_metadata(
|
||||
definition_account,
|
||||
@@ -983,7 +988,7 @@ fn test_call_new_definition_metadata_with_init_holding() {
|
||||
|
||||
#[should_panic(expected = "Master NFT Account must be authorized")]
|
||||
#[test]
|
||||
fn test_print_nft_master_account_must_be_authorized() {
|
||||
fn print_nft_master_account_must_be_authorized() {
|
||||
let master_account = AccountForTests::holding_account_uninit();
|
||||
let printed_account = AccountForTests::holding_account_uninit();
|
||||
let _post_states = print_nft(master_account, printed_account);
|
||||
@@ -991,7 +996,7 @@ fn test_print_nft_master_account_must_be_authorized() {
|
||||
|
||||
#[should_panic(expected = "Printed Account must be uninitialized")]
|
||||
#[test]
|
||||
fn test_print_nft_print_account_initialized() {
|
||||
fn print_nft_print_account_initialized() {
|
||||
let master_account = AccountForTests::holding_account_master_nft();
|
||||
let printed_account = AccountForTests::holding_account_init();
|
||||
let _post_states = print_nft(master_account, printed_account);
|
||||
@@ -999,7 +1004,7 @@ fn test_print_nft_print_account_initialized() {
|
||||
|
||||
#[should_panic(expected = "Invalid Token Holding data")]
|
||||
#[test]
|
||||
fn test_print_nft_master_nft_invalid_token_holding() {
|
||||
fn print_nft_master_nft_invalid_token_holding() {
|
||||
let master_account = AccountForTests::definition_account_auth();
|
||||
let printed_account = AccountForTests::holding_account_uninit();
|
||||
let _post_states = print_nft(master_account, printed_account);
|
||||
@@ -1007,7 +1012,7 @@ fn test_print_nft_master_nft_invalid_token_holding() {
|
||||
|
||||
#[should_panic(expected = "Invalid Token Holding provided as NFT Master Account")]
|
||||
#[test]
|
||||
fn test_print_nft_master_nft_not_nft_master_account() {
|
||||
fn print_nft_master_nft_not_nft_master_account() {
|
||||
let master_account = AccountForTests::holding_account_init();
|
||||
let printed_account = AccountForTests::holding_account_uninit();
|
||||
let _post_states = print_nft(master_account, printed_account);
|
||||
@@ -1015,14 +1020,14 @@ fn test_print_nft_master_nft_not_nft_master_account() {
|
||||
|
||||
#[should_panic(expected = "Insufficient balance to print another NFT copy")]
|
||||
#[test]
|
||||
fn test_print_nft_master_nft_insufficient_balance() {
|
||||
fn print_nft_master_nft_insufficient_balance() {
|
||||
let master_account = AccountForTests::holding_account_master_nft_insufficient_balance();
|
||||
let printed_account = AccountForTests::holding_account_uninit();
|
||||
let _post_states = print_nft(master_account, printed_account);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_print_nft_success() {
|
||||
fn print_nft_success() {
|
||||
let master_account = AccountForTests::holding_account_master_nft();
|
||||
let printed_account = AccountForTests::holding_account_uninit();
|
||||
let post_states = print_nft(master_account, printed_account);
|
||||
|
||||
@@ -4,6 +4,7 @@ use nssa_core::{
|
||||
};
|
||||
use token_core::TokenHolding;
|
||||
|
||||
#[must_use]
|
||||
pub fn transfer(
|
||||
sender: AccountWithMetadata,
|
||||
recipient: AccountWithMetadata,
|
||||
@@ -95,7 +96,7 @@ pub fn transfer(
|
||||
_ => {
|
||||
panic!("Mismatched token holding types for transfer");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let mut sender_post = sender.account;
|
||||
sender_post.data = Data::from(&sender_holding);
|
||||
|
||||
Reference in New Issue
Block a user