Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
155fde78
Unverified
Commit
155fde78
authored
1 year ago
by
Liam Aharon
Browse files
Options
Downloads
Patches
Plain Diff
add assets to mock
parent
cd65a375
No related merge requests found
Pipeline
#461713
failed with stages
in 3 minutes and 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/frame/asset-rewards/src/mock.rs
+20
-13
20 additions, 13 deletions
substrate/frame/asset-rewards/src/mock.rs
substrate/frame/asset-rewards/src/tests.rs
+4
-21
4 additions, 21 deletions
substrate/frame/asset-rewards/src/tests.rs
with
24 additions
and
34 deletions
substrate/frame/asset-rewards/src/mock.rs
+
20
−
13
View file @
155fde78
...
...
@@ -142,19 +142,26 @@ impl Config for MockRuntime {
pub
(
crate
)
fn
new_test_ext
()
->
sp_io
::
TestExternalities
{
let
mut
t
=
frame_system
::
GenesisConfig
::
<
MockRuntime
>
::
default
()
.build_storage
()
.unwrap
();
// pallet_assets::GenesisConfig::<MockRuntime, Instance1> {
// // Genesis assets: id, owner, is_sufficient, min_balance
// // pub assets: Vec<(T::AssetId, T::AccountId, bool, T::Balance)>,
// assets: vec![(1, 1, true, 10000)],
// // Genesis metadata: id, name, symbol, decimals
// // pub metadata: Vec<(T::AssetId, Vec<u8>, Vec<u8>, u8)>,
// metadata: vec![(1, b"test".to_vec(), b"TST".to_vec(), 18)],
// // Genesis accounts: id, account_id, balance
// // pub accounts: Vec<(T::AssetId, T::AccountId, T::Balance)>,
// accounts: vec![(1, 1, 10000)],
// }
// .assimilate_storage(&mut t)
// .unwrap();
pallet_assets
::
GenesisConfig
::
<
MockRuntime
,
Instance1
>
{
// Genesis assets: id, owner, is_sufficient, min_balance
// pub assets: Vec<(T::AssetId, T::AccountId, bool, T::Balance)>,
assets
:
vec!
[(
1
,
1
,
true
,
10000
)],
// Genesis metadata: id, name, symbol, decimals
// pub metadata: Vec<(T::AssetId, Vec<u8>, Vec<u8>, u8)>,
metadata
:
vec!
[(
1
,
b"test"
.to_vec
(),
b"TST"
.to_vec
(),
18
)],
// Genesis accounts: id, account_id, balance
// pub accounts: Vec<(T::AssetId, T::AccountId, T::Balance)>,
accounts
:
vec!
[
(
1
,
1
,
10000
),
(
1
,
2
,
20000
),
(
1
,
3
,
30000
),
(
1
,
4
,
40000
),
(
1
,
10
,
40000
),
(
1
,
20
,
40000
),
],
}
.assimilate_storage
(
&
mut
t
)
.unwrap
();
pallet_balances
::
GenesisConfig
::
<
MockRuntime
>
{
balances
:
vec!
[(
1
,
10000
),
(
2
,
20000
),
(
3
,
30000
),
(
4
,
40000
),
(
10
,
40000
),
(
20
,
40000
)],
...
...
This diff is collapsed.
Click to expand it.
substrate/frame/asset-rewards/src/tests.rs
+
4
−
21
View file @
155fde78
...
...
@@ -29,7 +29,6 @@ use sp_runtime::traits::BadOrigin;
/// Useful for tests when you don't care about customising, or reusing the pool params.
fn
create_default_pool
()
{
let
staking_asset_id
=
NativeOrWithId
::
<
u32
>
::
WithId
(
1
);
create_tokens
(
1
,
vec!
[
staking_asset_id
.clone
()]);
assert_ok!
(
StakingRewards
::
create_pool
(
RuntimeOrigin
::
signed
(
1
),
Box
::
new
(
staking_asset_id
),
...
...
@@ -40,17 +39,6 @@ fn create_default_pool() {
));
}
fn
create_tokens
(
owner
:
u128
,
tokens
:
Vec
<
NativeOrWithId
<
u32
>>
)
{
let
ed
=
1
;
for
token_id
in
tokens
{
let
asset_id
=
match
token_id
{
NativeOrWithId
::
WithId
(
id
)
=>
id
,
_
=>
unreachable!
(
"invalid token"
),
};
assert_ok!
(
Assets
::
force_create
(
RuntimeOrigin
::
root
(),
asset_id
,
owner
,
false
,
ed
));
}
}
fn
events
()
->
Vec
<
Event
<
MockRuntime
>>
{
let
result
=
System
::
events
()
.into_iter
()
...
...
@@ -85,8 +73,6 @@ mod create_pool {
let
reward_rate_per_block
=
100
;
let
expiry_block
=
200u64
;
create_tokens
(
user
,
vec!
[
reward_asset_id
.clone
()]);
assert_eq!
(
NextPoolId
::
<
MockRuntime
>
::
get
(),
0
);
assert_ok!
(
StakingRewards
::
create_pool
(
RuntimeOrigin
::
signed
(
user
),
...
...
@@ -243,7 +229,6 @@ mod create_pool {
let
reward_asset_id
=
NativeOrWithId
::
<
u32
>
::
WithId
(
1
);
let
reward_rate_per_block
=
100
;
let
expiry_block
=
100u64
;
create_tokens
(
user
,
vec!
[
reward_asset_id
.clone
()]);
assert_err!
(
StakingRewards
::
create_pool
(
RuntimeOrigin
::
signed
(
user
),
...
...
@@ -266,7 +251,6 @@ mod create_pool {
let
reward_asset_id
=
NativeOrWithId
::
<
u32
>
::
WithId
(
1
);
let
reward_rate_per_block
=
100
;
let
expiry_block
=
100u64
;
create_tokens
(
user
,
vec!
[
reward_asset_id
.clone
()]);
System
::
set_block_number
(
expiry_block
+
1u64
);
assert_err!
(
StakingRewards
::
create_pool
(
...
...
@@ -326,6 +310,9 @@ mod stake {
assert_eq!
(
Pools
::
<
MockRuntime
>
::
get
(
pool_id
)
.unwrap
()
.total_tokens_staked
,
1500
);
// TODO: Check user's frozen balance is updated
// Event is emitted.
assert_eq!
(
events
(),
[]);
});
}
...
...
@@ -334,12 +321,9 @@ mod stake {
new_test_ext
()
.execute_with
(||
{
let
user
=
1
;
let
staking_asset_id
=
NativeOrWithId
::
<
u32
>
::
WithId
(
1
);
create_tokens
(
user
,
vec!
[
staking_asset_id
.clone
()]);
let
non_existent_pool_id
=
999
;
assert_err!
(
StakingRewards
::
stake
(
RuntimeOrigin
::
signed
(
user
),
non_existent_pool_id
,
1000
),
StakingRewards
::
stake
(
RuntimeOrigin
::
signed
(
user
),
999
,
1000
),
Error
::
<
MockRuntime
>
::
NonExistentPool
);
});
...
...
@@ -616,7 +600,6 @@ fn integration() {
let
reward_asset_id
=
NativeOrWithId
::
<
u32
>
::
Native
;
let
reward_rate_per_block
=
100
;
let
expiry_block
=
25u64
.into
();
create_tokens
(
admin
,
vec!
[
staking_asset_id
.clone
()]);
assert_ok!
(
StakingRewards
::
create_pool
(
RuntimeOrigin
::
signed
(
admin
),
Box
::
new
(
staking_asset_id
.clone
()),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment