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
13bc601c
Commit
13bc601c
authored
7 years ago
by
Gav
Browse files
Options
Downloads
Patches
Plain Diff
Fix tests and avoid use of old keys.
parent
4ad8b95d
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/demo/executor/src/lib.rs
+31
-31
31 additions, 31 deletions
substrate/demo/executor/src/lib.rs
with
31 additions
and
31 deletions
substrate/demo/executor/src/lib.rs
+
31
−
31
View file @
13bc601c
...
...
@@ -39,7 +39,7 @@ mod tests {
use
super
::
Executor
;
use
substrate_executor
::
WasmExecutor
;
use
codec
::{
KeyedVec
,
Slicable
,
Joiner
};
use
keyring
::
Keyring
::{
self
,
One
,
Two
};
use
keyring
::
Keyring
::{
self
,
Alice
,
Bob
};
use
runtime_support
::
Hashable
;
use
demo_runtime
::
runtime
::
staking
::{
self
,
balance
,
BALANCE_OF
};
use
state_machine
::{
CodeExecutor
,
TestExternalities
};
...
...
@@ -60,9 +60,9 @@ mod tests {
fn
tx
()
->
UncheckedTransaction
{
let
transaction
=
Transaction
{
signed
:
On
e
.into
(),
signed
:
Alic
e
.into
(),
nonce
:
0
,
function
:
Function
::
StakingTransfer
(
Two
.into
(),
69
),
function
:
Function
::
StakingTransfer
(
Bob
.into
(),
69
),
};
let
signature
=
Keyring
::
from_raw_public
(
transaction
.signed
)
.unwrap
()
.sign
(
&
transaction
.encode
());
...
...
@@ -73,7 +73,7 @@ mod tests {
#[test]
fn
panic_execution_with_foreign_code_gives_error
()
{
let
mut
t
:
TestExternalities
=
map!
[
twox_128
(
&
On
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
68u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
twox_128
(
&
Alic
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
68u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
];
let
r
=
Executor
::
new
()
.call
(
&
mut
t
,
BLOATY_CODE
,
"execute_transaction"
,
&
vec!
[]
.and
(
&
Header
::
from_block_number
(
1u64
))
.and
(
&
tx
()));
...
...
@@ -83,7 +83,7 @@ mod tests {
#[test]
fn
panic_execution_with_native_equivalent_code_gives_error
()
{
let
mut
t
:
TestExternalities
=
map!
[
twox_128
(
&
On
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
68u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
twox_128
(
&
Alic
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
68u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
];
let
r
=
Executor
::
new
()
.call
(
&
mut
t
,
COMPACT_CODE
,
"execute_transaction"
,
&
vec!
[]
.and
(
&
Header
::
from_block_number
(
1u64
))
.and
(
&
tx
()));
...
...
@@ -93,30 +93,30 @@ mod tests {
#[test]
fn
successful_execution_with_native_equivalent_code_gives_ok
()
{
let
mut
t
:
TestExternalities
=
map!
[
twox_128
(
&
On
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
111u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
twox_128
(
&
Alic
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
111u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
];
let
r
=
Executor
::
new
()
.call
(
&
mut
t
,
COMPACT_CODE
,
"execute_transaction"
,
&
vec!
[]
.and
(
&
Header
::
from_block_number
(
1u64
))
.and
(
&
tx
()));
assert!
(
r
.is_ok
());
runtime_io
::
with_externalities
(
&
mut
t
,
||
{
assert_eq!
(
balance
(
&
On
e
),
42
);
assert_eq!
(
balance
(
&
Two
),
69
);
assert_eq!
(
balance
(
&
Alic
e
),
42
);
assert_eq!
(
balance
(
&
Bob
),
69
);
});
}
#[test]
fn
successful_execution_with_foreign_code_gives_ok
()
{
let
mut
t
:
TestExternalities
=
map!
[
twox_128
(
&
On
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
111u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
twox_128
(
&
Alic
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
111u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
];
let
r
=
Executor
::
new
()
.call
(
&
mut
t
,
BLOATY_CODE
,
"execute_transaction"
,
&
vec!
[]
.and
(
&
Header
::
from_block_number
(
1u64
))
.and
(
&
tx
()));
assert!
(
r
.is_ok
());
runtime_io
::
with_externalities
(
&
mut
t
,
||
{
assert_eq!
(
balance
(
&
On
e
),
42
);
assert_eq!
(
balance
(
&
Two
),
69
);
assert_eq!
(
balance
(
&
Alic
e
),
42
);
assert_eq!
(
balance
(
&
Bob
),
69
);
});
}
...
...
@@ -152,11 +152,11 @@ mod tests {
construct_block
(
1
,
[
69u8
;
32
]
.into
(),
hex!
(
"
6f0202ee141932f5cf9efad76d9200ec0ae98e2782335c5c7940be6a66bb9418
"
)
.into
(),
hex!
(
"
970ae19447bef129c88ee80c72797fa9dfeda4ca1a26d10102b669d776eb0ccf
"
)
.into
(),
vec!
[
Transaction
{
signed
:
On
e
.into
(),
signed
:
Alic
e
.into
(),
nonce
:
0
,
function
:
Function
::
StakingTransfer
(
Two
.into
(),
69
),
function
:
Function
::
StakingTransfer
(
Bob
.into
(),
69
),
}]
)
}
...
...
@@ -165,17 +165,17 @@ mod tests {
construct_block
(
2
,
block1
()
.1
,
hex!
(
"
04a2ca0ff5cdbe6a0ceb75009b4e707c8d052f28c95e9a7751ea814b13b95c92
"
)
.into
(),
hex!
(
"
347ece6ef0d193bd7c2bfbda17706b82eb24c0965f415784a44b138f0df034cd
"
)
.into
(),
vec!
[
Transaction
{
signed
:
Two
.into
(),
signed
:
Bob
.into
(),
nonce
:
0
,
function
:
Function
::
StakingTransfer
(
On
e
.into
(),
5
),
function
:
Function
::
StakingTransfer
(
Alic
e
.into
(),
5
),
},
Transaction
{
signed
:
On
e
.into
(),
signed
:
Alic
e
.into
(),
nonce
:
1
,
function
:
Function
::
StakingTransfer
(
Two
.into
(),
15
),
function
:
Function
::
StakingTransfer
(
Bob
.into
(),
15
),
}
]
)
...
...
@@ -188,15 +188,15 @@ mod tests {
Executor
::
new
()
.call
(
&
mut
t
,
COMPACT_CODE
,
"execute_block"
,
&
block1
()
.0
)
.unwrap
();
runtime_io
::
with_externalities
(
&
mut
t
,
||
{
assert_eq!
(
balance
(
&
On
e
),
42
);
assert_eq!
(
balance
(
&
Two
),
69
);
assert_eq!
(
balance
(
&
Alic
e
),
42
);
assert_eq!
(
balance
(
&
Bob
),
69
);
});
Executor
::
new
()
.call
(
&
mut
t
,
COMPACT_CODE
,
"execute_block"
,
&
block2
()
.0
)
.unwrap
();
runtime_io
::
with_externalities
(
&
mut
t
,
||
{
assert_eq!
(
balance
(
&
On
e
),
32
);
assert_eq!
(
balance
(
&
Two
),
79
);
assert_eq!
(
balance
(
&
Alic
e
),
32
);
assert_eq!
(
balance
(
&
Bob
),
79
);
});
}
...
...
@@ -207,22 +207,22 @@ mod tests {
WasmExecutor
.call
(
&
mut
t
,
COMPACT_CODE
,
"execute_block"
,
&
block1
()
.0
)
.unwrap
();
runtime_io
::
with_externalities
(
&
mut
t
,
||
{
assert_eq!
(
balance
(
&
On
e
),
42
);
assert_eq!
(
balance
(
&
Two
),
69
);
assert_eq!
(
balance
(
&
Alic
e
),
42
);
assert_eq!
(
balance
(
&
Bob
),
69
);
});
WasmExecutor
.call
(
&
mut
t
,
COMPACT_CODE
,
"execute_block"
,
&
block2
()
.0
)
.unwrap
();
runtime_io
::
with_externalities
(
&
mut
t
,
||
{
assert_eq!
(
balance
(
&
On
e
),
32
);
assert_eq!
(
balance
(
&
Two
),
79
);
assert_eq!
(
balance
(
&
Alic
e
),
32
);
assert_eq!
(
balance
(
&
Bob
),
79
);
});
}
#[test]
fn
panic_execution_gives_error
()
{
let
mut
t
:
TestExternalities
=
map!
[
twox_128
(
&
On
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
68u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
twox_128
(
&
Alic
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
68u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
];
let
foreign_code
=
include_bytes!
(
"../../runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm"
);
...
...
@@ -233,7 +233,7 @@ mod tests {
#[test]
fn
successful_execution_gives_ok
()
{
let
mut
t
:
TestExternalities
=
map!
[
twox_128
(
&
On
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
111u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
twox_128
(
&
Alic
e
.to_raw_public
()
.to_keyed_vec
(
BALANCE_OF
))
.to_vec
()
=>
vec!
[
111u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
];
let
foreign_code
=
include_bytes!
(
"../../runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm"
);
...
...
@@ -241,8 +241,8 @@ mod tests {
assert!
(
r
.is_ok
());
runtime_io
::
with_externalities
(
&
mut
t
,
||
{
assert_eq!
(
balance
(
&
On
e
),
42
);
assert_eq!
(
balance
(
&
Two
),
69
);
assert_eq!
(
balance
(
&
Alic
e
),
42
);
assert_eq!
(
balance
(
&
Bob
),
69
);
});
}
}
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