Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion ref-exchange/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ref-exchange"
version = "1.3.1"
version = "1.3.2"
authors = ["Illia Polosukhin <[email protected]>"]
edition = "2018"
publish = false
Expand Down
3 changes: 3 additions & 0 deletions ref-exchange/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release Notes

### Version 1.3.2
1. Apply FIX for issue#56;

### Version 1.3.1
1. Apply HOTFIX in v1.0.3;

Expand Down
2 changes: 2 additions & 0 deletions ref-exchange/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ impl Contract {
);
}
}
} else {
account.near_amount += env::attached_deposit();
}
let referral_id = referral_id.map(|r| r.into());
let result =
Expand Down
16 changes: 8 additions & 8 deletions ref-exchange/tests/test_account_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn account_upgrade_enough_storage() {
)
.assert_success();

assert_eq!(get_version(&pool), String::from("1.3.1"));
assert_eq!(get_version(&pool), String::from("1.3.2"));

let ss = get_storage_state(&pool, user.valid_account_id()).unwrap();
assert_eq!(ss.deposit.0, to_yocto("0.00350"));
Expand Down Expand Up @@ -154,11 +154,11 @@ fn account_upgrade_enough_storage() {
assert_eq!(get_error_count(&out_come), 0);

let ss = get_storage_state(&pool, user.valid_account_id()).unwrap();
assert_eq!(ss.deposit.0, to_yocto("0.00482"));
assert_eq!(ss.deposit.0, to_yocto("0.00482")+1);
assert_eq!(ss.usage.0, to_yocto("0.00482"));
let sb = get_storage_balance(&pool, user.valid_account_id()).unwrap();
assert_eq!(sb.total.0, to_yocto("0.00482"));
assert_eq!(sb.available.0, 0);
assert_eq!(sb.total.0, to_yocto("0.00482")+1);
assert_eq!(sb.available.0, 1);

assert_eq!(get_deposits(&pool,
user.valid_account_id())
Expand All @@ -183,11 +183,11 @@ fn account_upgrade_enough_storage() {
assert_eq!(get_error_count(&out_come), 0);

let ss = get_storage_state(&pool, user.valid_account_id()).unwrap();
assert_eq!(ss.deposit.0, to_yocto("0.00546"));
assert_eq!(ss.deposit.0, to_yocto("0.00546")+1);
assert_eq!(ss.usage.0, to_yocto("0.00546"));
let sb = get_storage_balance(&pool, user.valid_account_id()).unwrap();
assert_eq!(sb.total.0, to_yocto("0.00546"));
assert_eq!(sb.available.0, 0);
assert_eq!(sb.total.0, to_yocto("0.00546")+1);
assert_eq!(sb.available.0, 1);

assert_eq!(get_deposits(&pool,
user.valid_account_id())
Expand All @@ -208,7 +208,7 @@ fn account_upgrade_not_enough_storage() {
0,
)
.assert_success();
assert_eq!(get_version(&pool), String::from("1.3.1"));
assert_eq!(get_version(&pool), String::from("1.3.2"));

// deposit would fail
let out_come = call!(
Expand Down
2 changes: 1 addition & 1 deletion ref-exchange/tests/test_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn test_upgrade() {
.assert_success();
let metadata = get_metadata(&pool);
// println!("{:#?}", metadata);
assert_eq!(metadata.version, "1.3.1".to_string());
assert_eq!(metadata.version, "1.3.2".to_string());
assert_eq!(metadata.state, RunningState::Running);

// Upgrade to the same code migration is skipped.
Expand Down
42 changes: 42 additions & 0 deletions ref-exchange/tests/test_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use near_sdk_sim::{
use ref_exchange::{ContractContract as Exchange, PoolInfo, SwapAction};
use test_token::ContractContract as TestToken;

use crate::common::utils::get_storage_state;
pub mod common;

near_sdk_sim::lazy_static_include::lazy_static_include_bytes! {
TEST_TOKEN_WASM_BYTES => "../res/test_token.wasm",
EXCHANGE_WASM_BYTES => "../res/ref_exchange_release.wasm",
Expand Down Expand Up @@ -230,6 +233,45 @@ fn test_swap() {
assert_eq!(balance2, to_yocto("991"));
}

#[test]
fn test_swap_with_deposit() {
let (root, _owner, pool, _token1, _token2) = setup_pool_with_liquidity();
assert_eq!(
view!(pool.get_pool(0)).unwrap_json::<PoolInfo>(),
PoolInfo {
pool_kind: "SIMPLE_POOL".to_string(),
token_account_ids: vec![dai(), eth()],
amounts: vec![to_yocto("5").into(), to_yocto("10").into()],
total_fee: 30,
shares_total_supply: to_yocto("1").into(),
}
);

assert_eq!(get_storage_state(&pool, root.valid_account_id()).unwrap().deposit.0, to_yocto("1"));
assert_eq!(root.account().unwrap().amount / 10_u128.pow(22), 999999748_98);

call!(
root,
pool.swap(
vec![SwapAction {
pool_id: 0,
token_in: dai(),
amount_in: Some(U128(to_yocto("1"))),
token_out: eth(),
min_amount_out: U128(1)
}],
None
),
deposit = to_yocto("100")
)
.assert_success();

// deposit near should plus 100
assert_eq!(get_storage_state(&pool, root.valid_account_id()).unwrap().deposit.0, to_yocto("101"));
// account amount should decrease a little more than 100
assert_eq!(root.account().unwrap().amount / 10_u128.pow(22), 999999648_97);
}

#[test]
fn test_withdraw_failure() {
let root = init_simulator(None);
Expand Down
Binary file modified res/ref_exchange_release.wasm
Binary file not shown.