Skip to content

Commit 5ec047a

Browse files
committed
fix lockup indexing
1 parent ac5faf3 commit 5ec047a

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

ft-lockup-contract/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Contract {
107107

108108
impl Contract {
109109
pub fn next_index(&mut self) -> LockupIndex {
110-
while self.lockups.keys().any(|key| key == self.index) {
110+
if self.lockups.get(&self.index).is_some() {
111111
self.index = self
112112
.index
113113
.checked_add(1)

ft-token-contract/src/lis_token.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ mod tests {
104104
fn mint_time_check() {
105105
let owner_id = accounts(0);
106106
let staking_id = accounts(1);
107+
let lockup_id = accounts(2);
107108
let initial_total_supply = 3_000_000_000 * 10_u128.pow(12);
108109
let context = VMContextBuilder::new();
109110

110111
// init contract
111112
testing_env!(context.clone().block_timestamp(WEEK.0).build());
112-
let mut contract = Contract::new(Some(owner_id.clone()), None, staking_id);
113+
let mut contract = Contract::new(Some(owner_id.clone()), None, staking_id, lockup_id);
113114
assert_eq!(contract.ft_total_supply().0, initial_total_supply);
114115

115116
// wait week
@@ -170,12 +171,13 @@ mod tests {
170171
fn mint_before_new_week() {
171172
let owner_id = accounts(0);
172173
let staking_id = accounts(1);
174+
let lockup_id = accounts(2);
173175
let initial_total_supply = 3_000_000_000 * 10_u128.pow(12);
174176
let context = VMContextBuilder::new();
175177

176178
// init contract
177179
testing_env!(context.clone().block_timestamp(WEEK.0).build());
178-
let mut contract = Contract::new(Some(owner_id.clone()), None, staking_id);
180+
let mut contract = Contract::new(Some(owner_id.clone()), None, staking_id, lockup_id);
179181
assert_eq!(contract.ft_total_supply().0, initial_total_supply);
180182

181183
// wait 3 days
@@ -193,11 +195,12 @@ mod tests {
193195
fn can_mint_only_owner() {
194196
let owner_id = accounts(0);
195197
let staking_id = accounts(1);
198+
let lockup_id = accounts(2);
196199
let context = VMContextBuilder::new();
197200

198201
// init contract
199202
testing_env!(context.clone().block_timestamp(WEEK.0).build());
200-
let mut contract = Contract::new(Some(owner_id.clone()), None, staking_id);
203+
let mut contract = Contract::new(Some(owner_id.clone()), None, staking_id, lockup_id);
201204

202205
// wait week
203206
testing_env!(context

ft-token-contract/src/owner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Contract {
7272
// Initiating receiver's call and the callback
7373
ext_ft_receiver::ext(receiver_id.clone())
7474
.with_static_gas(env::prepaid_gas() - GAS_FOR_FT_TRANSFER_CALL)
75-
.ft_on_transfer(sender_id.clone(), amount.into(), msg)
75+
.ft_on_transfer(env::predecessor_account_id(), amount.into(), msg)
7676
.then(
7777
ext_ft_resolver::ext(env::current_account_id())
7878
.with_static_gas(GAS_FOR_RESOLVE_TRANSFER)

ft-token-contract/tests/utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ use workspaces::{network::Sandbox, AccountId, Contract, Worker};
44

55
pub const CONTRACT_ACCOUNT: &str = "token.v1.realisnetwork.near";
66
pub const STAKING_ACCOUNT: &str = "staking.v1.realisnetwork.near";
7+
pub const LOCKUP_ACCOUNT: &str = "lockup.v1.realisnetwork.near";
78
pub const SPEC_METADATA: &str = "ft-1.0.1";
89

910
pub async fn pull_contract(worker: &Worker<Sandbox>) -> anyhow::Result<Contract> {
1011
let mainnet = workspaces::mainnet_archival().await?;
1112
let contract_id: AccountId = CONTRACT_ACCOUNT.parse()?;
1213
let contract = worker
1314
.import_contract(&contract_id, &mainnet)
14-
.initial_balance(parse_near!("1000 N"))
15+
.initial_balance(parse_near!("5000 N"))
1516
.transact()
1617
.await?;
1718

1819
contract
1920
.call("new")
20-
.args_json(serde_json::json!({ "staking_id": STAKING_ACCOUNT }))
21+
.args_json(
22+
serde_json::json!({ "staking_id": STAKING_ACCOUNT, "lockup_id": LOCKUP_ACCOUNT }),
23+
)
2124
.transact()
2225
.await?
2326
.into_result()?;

scripts/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ then
112112
--initArgs '{"token_account_id": "'$TOKEN_CONTRACT_ID'", "deposit_whitelist": ["'$OWNER_ID'", "'$STAKING_CONTRACT_ID'"]}' \
113113
--initGas 300000000000000
114114
echo "Register in token contract"
115-
near call $TOKEN_CONTRACT_ID register '{"account_id": "'$LOCKUP_CONTRACT_ID'"}' --accountId $OWNER_ID
115+
near call $TOKEN_CONTRACT_ID storage_deposit '{"account_id": "'$LOCKUP_CONTRACT_ID'"}' --accountId $OWNER_ID --deposit 1
116116
else
117117
echo "Updating contract"
118118
echo y | near deploy --accountId $LOCKUP_CONTRACT_ID \

test-utils/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub async fn pull(
3535
let contract_id: AccountId = TOKEN_CONTRACT_ACCOUNT.parse()?;
3636
let contract = worker
3737
.import_contract(&contract_id, &mainnet)
38-
.initial_balance(parse_near!("1000 N"))
38+
.initial_balance(parse_near!("5000 N"))
3939
.transact()
4040
.await?;
4141

0 commit comments

Comments
 (0)