Skip to content

Commit

Permalink
Fix: set keep_alive false in farming transfer (#1879)
Browse files Browse the repository at this point in the history
* set keep_alive false

* add --user root to srtool.sh

* update srtool

* update typos

* add test
  • Loading branch information
mclyk authored Sep 20, 2022
1 parent 4f2091f commit f48a804
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/srtool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- uses: actions/checkout@v3
- name: Srtool build
id: srtool_build
uses: chevdor/srtool-actions@v0.3.0
uses: chevdor/srtool-actions@v0.5.0
with:
chain: ${{ matrix.chain }}
tag: 1.62.0
Expand Down
10 changes: 5 additions & 5 deletions pallets/farming/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ pub mod pallet {

ensure!(pool_info.is_active, Error::<T>::PoolIsNotActive);

T::Assets::transfer(asset, &who, &asset_pool_account, amount, true)?;
T::Assets::transfer(asset, &who, &asset_pool_account, amount, false)?;

pool_info.total_deposited = pool_info
.total_deposited
Expand Down Expand Up @@ -514,7 +514,7 @@ pub mod pallet {
&asset_pool_account,
&who,
amount,
true,
false,
)?;
} else {
user_position
Expand Down Expand Up @@ -579,7 +579,7 @@ pub mod pallet {

if total_amount > 0 {
let asset_pool_account = Self::pool_account_id(asset)?;
T::Assets::transfer(asset, &asset_pool_account, &who, total_amount, true)?;
T::Assets::transfer(asset, &asset_pool_account, &who, total_amount, false)?;
}

Self::deposit_event(Event::<T>::AssetsRedeem(
Expand Down Expand Up @@ -629,7 +629,7 @@ pub mod pallet {
&asset_pool_account,
&who,
reward_amount,
true,
false,
)?;
user_position.reward_amount = 0;
}
Expand Down Expand Up @@ -720,7 +720,7 @@ pub mod pallet {
&payer,
&asset_pool_account,
amount,
true,
false,
)?;
}

Expand Down
54 changes: 54 additions & 0 deletions pallets/farming/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,3 +1018,57 @@ fn edge_case_reward_token_decimal_too_big() {
));
})
}

#[test]
fn pool_failed() {
new_test_ext().execute_with(|| {
let deposit_balance = 100_000_000;
assert_ok!(Farming::deposit(
RawOrigin::Signed(ALICE).into(),
STAKE_TOKEN,
REWARD_TOKEN,
LOCK_DURATION,
deposit_balance,
));

assert_ok!(Farming::deposit(
RawOrigin::Signed(BOB).into(),
STAKE_TOKEN,
REWARD_TOKEN,
LOCK_DURATION,
deposit_balance,
));

assert_ok!(Farming::withdraw(
RawOrigin::Signed(ALICE).into(),
STAKE_TOKEN,
REWARD_TOKEN,
LOCK_DURATION,
deposit_balance,
));

assert_ok!(Farming::withdraw(
RawOrigin::Signed(BOB).into(),
STAKE_TOKEN,
REWARD_TOKEN,
LOCK_DURATION,
deposit_balance,
));

run_to_block(200);

assert_ok!(Farming::redeem(
RawOrigin::Signed(ALICE).into(),
STAKE_TOKEN,
REWARD_TOKEN,
LOCK_DURATION,
));

assert_ok!(Farming::redeem(
RawOrigin::Signed(BOB).into(),
STAKE_TOKEN,
REWARD_TOKEN,
LOCK_DURATION,
));
})
}
1 change: 1 addition & 0 deletions scripts/srtool-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ docker run --rm -it \
-e BUILD_OPTS="$BUILD_OPTS" \
-v $PWD:/build \
-v $TMPDIR/cargo:/cargo-home \
--user root \
--network=host \
paritytech/srtool:$RUSTC_VERSION
1 change: 1 addition & 0 deletions typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ extend-exclude = ["scripts/polkadot-launch/*", "resources/specs/*", "scripts/evm

[default.extend-words]
accured = "accured"
Nd = "Nd"

0 comments on commit f48a804

Please sign in to comment.