-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve structure of swaps fuzz tests, add valid pool creation (#542)
* Improve structure of swaps fuzz tests, add valid pool creation Co-authored-by: Malte Kliemann <mail@maltekliemann.com>
- Loading branch information
1 parent
fc3de00
commit 464180f
Showing
16 changed files
with
620 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,7 @@ | |
**/artifacts/ | ||
|
||
# NPM | ||
**/node_modules/ | ||
**/node_modules/ | ||
|
||
# Visual Studio Code | ||
.vscode |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use zeitgeist_primitives::{traits::Swaps as SwapsTrait, types::ScoringRule}; | ||
|
||
use zrml_swaps::mock::{ExtBuilder, Swaps}; | ||
|
||
mod utils; | ||
use utils::{construct_asset, PoolCreationData}; | ||
|
||
fuzz_target!(|data: PoolCreationData| { | ||
let mut ext = ExtBuilder::default().build(); | ||
let _ = ext.execute_with(|| { | ||
let _ = Swaps::create_pool( | ||
data.origin, | ||
data.assets.into_iter().map(construct_asset).collect(), | ||
construct_asset(data.base_asset), | ||
data.market_id, | ||
ScoringRule::CPMM, | ||
data.swap_fee, | ||
data.amount, | ||
data.weights, | ||
); | ||
}); | ||
let _ = ext.commit_all(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use zrml_swaps::mock::{ExtBuilder, Origin, Swaps}; | ||
|
||
mod utils; | ||
use orml_traits::MultiCurrency; | ||
use utils::{construct_asset, GeneralPoolData}; | ||
use zeitgeist_primitives::types::{Asset, SerdeWrapper}; | ||
use zrml_swaps::mock::Shares; | ||
|
||
fuzz_target!(|data: GeneralPoolData| { | ||
let mut ext = ExtBuilder::default().build(); | ||
let _ = ext.execute_with(|| { | ||
// ensure that the account origin has a sufficient balance | ||
// use orml_traits::MultiCurrency; required for this | ||
for a in &data.pool_creation.assets { | ||
let _ = Shares::deposit( | ||
construct_asset(*a), | ||
&data.pool_creation.origin, | ||
data.pool_creation.amount, | ||
); | ||
} | ||
let pool_creator = data.pool_creation.origin; | ||
let pool_id = data.pool_creation.create_pool(); | ||
// to exit a pool, origin also needs to have the pool tokens of the pool that they're exiting | ||
let _ = Shares::deposit( | ||
Asset::PoolShare(SerdeWrapper(pool_id)), | ||
&pool_creator, | ||
data.pool_amount, | ||
); | ||
let _ = Swaps::pool_exit( | ||
Origin::signed(data.origin), | ||
pool_id, | ||
data.pool_amount, | ||
data.asset_bounds, | ||
); | ||
}); | ||
let _ = ext.commit_all(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use zrml_swaps::mock::{ExtBuilder, Origin, Swaps}; | ||
|
||
mod utils; | ||
use orml_traits::MultiCurrency; | ||
use utils::{construct_asset, ExactAssetAmountData}; | ||
use zrml_swaps::mock::Shares; | ||
|
||
use zeitgeist_primitives::types::{Asset, SerdeWrapper}; | ||
|
||
fuzz_target!(|data: ExactAssetAmountData| { | ||
let mut ext = ExtBuilder::default().build(); | ||
let _ = ext.execute_with(|| { | ||
// ensure that the account origin has a sufficient balance | ||
// use orml_traits::MultiCurrency; required for this | ||
for a in &data.pool_creation.assets { | ||
let _ = Shares::deposit( | ||
construct_asset(*a), | ||
&data.pool_creation.origin, | ||
data.pool_creation.amount, | ||
); | ||
} | ||
|
||
let pool_creator = data.pool_creation.origin; | ||
let pool_id = data.pool_creation.create_pool(); | ||
// to exit a pool, origin also needs to have the pool tokens of the pool that they're exiting | ||
let _ = Shares::deposit( | ||
Asset::PoolShare(SerdeWrapper(pool_id)), | ||
&pool_creator, | ||
data.pool_amount, | ||
); | ||
let _ = Swaps::pool_exit_with_exact_asset_amount( | ||
Origin::signed(data.origin), | ||
pool_id, | ||
construct_asset(data.asset), | ||
data.asset_amount, | ||
data.pool_amount, | ||
); | ||
}); | ||
let _ = ext.commit_all(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use zrml_swaps::mock::{ExtBuilder, Origin, Swaps}; | ||
|
||
mod utils; | ||
use orml_traits::MultiCurrency; | ||
use utils::{construct_asset, ExactAmountData}; | ||
use zeitgeist_primitives::types::{Asset, SerdeWrapper}; | ||
use zrml_swaps::mock::Shares; | ||
|
||
fuzz_target!(|data: ExactAmountData| { | ||
let mut ext = ExtBuilder::default().build(); | ||
let _ = ext.execute_with(|| { | ||
// ensure that the account origin has a sufficient balance | ||
// use orml_traits::MultiCurrency; required for this | ||
for a in &data.pool_creation.assets { | ||
let _ = Shares::deposit( | ||
construct_asset(*a), | ||
&data.pool_creation.origin, | ||
data.pool_creation.amount, | ||
); | ||
} | ||
|
||
let pool_creator = data.pool_creation.origin; | ||
let pool_id = data.pool_creation.create_pool(); | ||
// to exit a pool, origin also needs to have the pool tokens of the pool that they're exiting | ||
let _ = Shares::deposit( | ||
Asset::PoolShare(SerdeWrapper(pool_id)), | ||
&pool_creator, | ||
data.pool_amount, | ||
); | ||
let _ = Swaps::pool_exit_with_exact_pool_amount( | ||
Origin::signed(data.origin), | ||
pool_id, | ||
construct_asset(data.asset), | ||
data.pool_amount, | ||
data.asset_amount, | ||
); | ||
}); | ||
let _ = ext.commit_all(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
|
||
use utils::GeneralPoolData; | ||
use zrml_swaps::mock::{ExtBuilder, Origin, Swaps}; | ||
mod utils; | ||
use utils::construct_asset; | ||
use zrml_swaps::mock::Shares; | ||
|
||
use orml_traits::MultiCurrency; | ||
|
||
fuzz_target!(|data: GeneralPoolData| { | ||
let mut ext = ExtBuilder::default().build(); | ||
let _ = ext.execute_with(|| { | ||
// ensure that the account origin has a sufficient balance | ||
// use orml_traits::MultiCurrency; required for this | ||
for a in &data.pool_creation.assets { | ||
let _ = Shares::deposit( | ||
construct_asset(*a), | ||
&data.pool_creation.origin, | ||
data.pool_creation.amount, | ||
); | ||
} | ||
let pool_id = data.pool_creation.create_pool(); | ||
// join a pool with a valid pool id | ||
let _ = Swaps::pool_join( | ||
Origin::signed(data.origin), | ||
pool_id, | ||
data.pool_amount, | ||
data.asset_bounds, | ||
); | ||
}); | ||
|
||
let _ = ext.commit_all(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use zrml_swaps::mock::{ExtBuilder, Origin, Swaps}; | ||
|
||
use utils::ExactAssetAmountData; | ||
mod utils; | ||
use orml_traits::MultiCurrency; | ||
use utils::construct_asset; | ||
use zrml_swaps::mock::Shares; | ||
|
||
fuzz_target!(|data: ExactAssetAmountData| { | ||
let mut ext = ExtBuilder::default().build(); | ||
let _ = ext.execute_with(|| { | ||
// ensure that the account origin has a sufficient balance | ||
// use orml_traits::MultiCurrency; required for this | ||
for a in &data.pool_creation.assets { | ||
let _ = Shares::deposit( | ||
construct_asset(*a), | ||
&data.pool_creation.origin, | ||
// In order to successfully join the pool, data.asset_amount more tokens needed | ||
data.pool_creation.amount.saturating_add(data.asset_amount), | ||
); | ||
} | ||
let pool_id = data.pool_creation.create_pool(); | ||
let _ = Swaps::pool_join_with_exact_asset_amount( | ||
Origin::signed(data.origin), | ||
pool_id, | ||
construct_asset(data.asset), | ||
data.asset_amount, | ||
data.pool_amount, | ||
); | ||
}); | ||
let _ = ext.commit_all(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use zrml_swaps::mock::{ExtBuilder, Origin, Swaps}; | ||
|
||
use utils::ExactAmountData; | ||
mod utils; | ||
use orml_traits::MultiCurrency; | ||
use utils::construct_asset; | ||
use zrml_swaps::mock::Shares; | ||
|
||
fuzz_target!(|data: ExactAmountData| { | ||
let mut ext = ExtBuilder::default().build(); | ||
let _ = ext.execute_with(|| { | ||
// ensure that the account origin has a sufficient balance | ||
// use orml_traits::MultiCurrency; required for this | ||
for a in &data.pool_creation.assets { | ||
let _ = Shares::deposit( | ||
construct_asset(*a), | ||
&data.pool_creation.origin, | ||
// In order to successfully join the pool, data.asset_amount more tokens needed | ||
data.pool_creation.amount.saturating_add(data.asset_amount), | ||
); | ||
} | ||
let pool_id = data.pool_creation.create_pool(); | ||
let _ = Swaps::pool_join_with_exact_pool_amount( | ||
Origin::signed(data.origin), | ||
pool_id, | ||
construct_asset(data.asset), | ||
data.pool_amount, | ||
data.asset_amount, | ||
); | ||
}); | ||
let _ = ext.commit_all(); | ||
}); |
Oops, something went wrong.