Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • nodes/rust/duniter-v2s
  • llaq/lc-core-substrate
  • pini-gh/duniter-v2s
  • vincentux/duniter-v2s
  • mildred/duniter-v2s
  • d0p1/duniter-v2s
  • bgallois/duniter-v2s
  • Nicolas80/duniter-v2s
8 results
Show changes
Commits on Source (18)
Showing
with 1189 additions and 1132 deletions
......@@ -3,5 +3,6 @@ cucumber = "test -p duniter-end2end-tests --test cucumber_tests --"
sanity-gdev = "test -p duniter-live-tests --test sanity_gdev -- --nocapture"
tu = "test --workspace --exclude duniter-end2end-tests --exclude duniter-live-tests"
tb = "test --features runtime-benchmarks -p"
rbp = "run --release --features runtime-benchmarks -- benchmark pallet --chain=dev --steps=50 --repeat=20 --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=. --pallet"
xtask = "run --package xtask --"
This diff is collapsed.
......@@ -7,7 +7,7 @@ homepage = 'https://substrate.dev'
license = 'AGPL-3.0'
name = 'duniter'
repository = 'https://git.duniter.org/nodes/rust/duniter-v2s'
version = '0.1.0'
version = '0.3.0'
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
......@@ -40,16 +40,16 @@ try-runtime = [
[build-dependencies]
clap = { version = "3.0" }
#clap_complete = { version = "3.0" }
substrate-build-script-utils = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23' }
substrate-build-script-utils = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
[dev-dependencies]
rusty-hook = "^0.11.2"
# Dependencies for specific targets
[target.'cfg(any(target_arch="x86_64", target_arch="aarch64"))'.dependencies]
sc-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23", features = ["wasmtime"] }
sc-service = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23", features = ["wasmtime"] }
sp-trie = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23", features = ["memory-tracker"] }
sc-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26", default-features = false, features = ["wasmtime"] }
sc-service = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26", default-features = false, features = ["wasmtime"] }
sp-trie = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26", features = ["memory-tracker"] }
[dependencies]
......@@ -67,7 +67,7 @@ clap = { version = "3.0", features = ["derive"] }
clap_complete = { version = "3" }
futures = { version = "0.3.1", features = ["compat"] }
hex = "0.4.3"
jsonrpsee = { version = "0.13.0", features = ["server"] }
jsonrpsee = { version = "0.14.0", features = ["server"] }
lazy_static = "1.4.0"
log = "0.4"
maplit = '1.0.2'
......@@ -77,49 +77,49 @@ serde_json = "1.0.64"
tracing-core = "=0.1.26"
# substrate dependencies
frame-benchmarking = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
frame-benchmarking-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
pallet-grandpa = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
pallet-transaction-payment-rpc = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-basic-authorship = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-chain-spec = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-client-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-consensus = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
babe = { package = "sc-consensus-babe", git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
manual-seal = { package = "sc-consensus-manual-seal", git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-consensus-uncles = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-executor = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-finality-grandpa = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-keystore = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-network = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-rpc-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-service = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-telemetry = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-transaction-pool = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sc-transaction-pool-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-authority-discovery = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-block-builder = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-blockchain = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-consensus = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-consensus-babe = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-core = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-finality-grandpa = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-inherents = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-io = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-offchain = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-keyring = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-keystore = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-runtime = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-session = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-storage = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-timestamp = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-transaction-pool = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
sp-trie = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
substrate-frame-rpc-system = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
try-runtime-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23", optional = true }
frame-benchmarking = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
frame-benchmarking-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
pallet-grandpa = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
pallet-transaction-payment-rpc = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-basic-authorship = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-chain-spec = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26", default-features = false }
sc-client-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-consensus = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
babe = { package = "sc-consensus-babe", git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
manual-seal = { package = "sc-consensus-manual-seal", git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-consensus-uncles = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-executor = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-finality-grandpa = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-keystore = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-network = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-rpc-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-service = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26", default-features = false }
sc-telemetry = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-transaction-pool = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sc-transaction-pool-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-authority-discovery = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-block-builder = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-blockchain = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-consensus = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-consensus-babe = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-core = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-finality-grandpa = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-inherents = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-io = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-offchain = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-keyring = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-keystore = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-runtime = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-session = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-storage = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-timestamp = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-transaction-pool = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
sp-trie = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
substrate-frame-rpc-system = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
try-runtime-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26", optional = true }
[workspace]
resolver = "2"
......@@ -133,6 +133,7 @@ members = [
'pallets/duniter-wot',
'pallets/identity',
'pallets/membership',
'pallets/oneshot-account',
'pallets/authority-members',
'pallets/universal-dividend',
'pallets/upgrade-origin',
......@@ -176,7 +177,6 @@ httparse = { opt-level = 3 }
integer-sqrt = { opt-level = 3 }
keccak = { opt-level = 3 }
libm = { opt-level = 3 }
librocksdb-sys = { opt-level = 3 }
libsecp256k1 = { opt-level = 3 }
libz-sys = { opt-level = 3 }
mio = { opt-level = 3 }
......
......@@ -2,7 +2,7 @@ version: "3.4"
services:
duniter-rpc:
image: duniter/duniter-v2s:v0.1.0
image: duniter/duniter-v2s:v0.2.0
restart: unless-stopped
ports:
# telemetry
......@@ -19,8 +19,6 @@ services:
environment:
- DUNITER_CHAIN_NAME=gdev
command:
- "--execution"
- "Wasm"
- "--node-key-file"
- "/var/lib/duniter/node.key"
- "--public-addr"
......
......@@ -2,7 +2,7 @@ version: "3.4"
services:
duniter-rpc:
image: duniter/duniter-v2s:v0.1.0
image: duniter/duniter-v2s:v0.2.0
restart: unless-stopped
ports:
# telemetry
......@@ -19,18 +19,17 @@ services:
environment:
- DUNITER_CHAIN_NAME=gdev
command:
- "--execution=Wasm"
- "--node-key-file=/var/lib/duniter/node.key"
- "--public-addr"
# SERVER_DOMAIN should be replaced by a domain name that point on your server
#
# The PEER_ID should be replaced by the output of this command:
# docker run --rm -it --entrypoint -v $PWD/duniter-rpc/:/var/lib/duniter/ duniter duniter/duniter-v2s:v0.1.0 key generate-node-key --file /var/lib/duniter/node-key.txt
# docker run --rm -it --entrypoint -v $PWD/duniter-rpc/:/var/lib/duniter/ duniter duniter/duniter-v2s:v0.2.0 key generate-node-key --file /var/lib/duniter/node.key
- "/dns/${SERVER_DOMAIN?SERVER_DOMAIN should be set}/tcp/30333/p2p/${PEER_ID?PEER_ID should be set}"
- "--rpc-cors=all"
duniter-validator:
image: duniter/duniter-v2s:v0.1.0
image: duniter/duniter-v2s:v0.2.0
restart: unless-stopped
ports:
# telemetry
......@@ -47,13 +46,13 @@ services:
environment:
- DUNITER_CHAIN_NAME=gdev
command:
- "--execution=Wasm"
- "--node-key-file=/var/lib/duniter/node.key"
- "--public-addr"
- "--pruning=14400"
# SERVER_DOMAIN should be replaced by a domain name that point on your server
#
# The PEER_ID should be replaced by the output of this command:
# docker run --rm -it --entrypoint -v $PWD/duniter-rpc/:/var/lib/duniter/ duniter duniter/duniter-v2s:v0.1.0 key generate-node-key --file /var/lib/duniter/node-key.txt
# The VALIDATOR_PEER_ID should be replaced by the output of this command:
# docker run --rm -it --entrypoint -v $PWD/duniter-rpc/:/var/lib/duniter/ duniter duniter/duniter-v2s:v0.2.0 key generate-node-key --file /var/lib/duniter/node.key
- "/dns/${SERVER_DOMAIN?SERVER_DOMAIN should be set}/tcp/30333/p2p/${VALIDATOR_PEER_ID?VALIDATOR_PEER_ID should be set}"
- "--rpc-cors=all"
- "--rpc-methods=Unsafe"
......
......@@ -5,7 +5,7 @@
### Duniter part
- Add this docker-compose on your server :
[docker/compose/gdev-rpc.docker-compose.yml](https://git.duniter.org/nodes/rust/duniter-v2s/-/blob/master/docker/compose/gdev-rpc.docker-compose.yml)
[docker/compose/gdev-rpc.docker-compose.yml](https://git.duniter.org/nodes/rust/duniter-v2s/-/blob/master/docker/compose/gdev-mirror.docker-compose.yml)
- Rename the file : `mv gdev-mirror.docker-compose.yml docker-compose.yml`
- In the same folder, create a `.env` file that defime environment variables `SERVER_DOMAIN` and `PEER_ID`:
```
......@@ -13,7 +13,7 @@ SERVER_DOMAIN=YOUR_DOMAIN
PEER_ID=YOUR_PEER_ID
```
Your `PEER_ID` shoud be generated with this command: `docker run --rm -it --entrypoint duniter -v $PWD:/var/lib/duniter/ duniter/duniter-v2s:v0.1.0 key generate-node-key --file /var/lib/duniter/node.key`
Your `PEER_ID` shoud be generated with this command: `docker run --rm -it --entrypoint duniter -v $PWD:/var/lib/duniter/ duniter/duniter-v2s:v0.2.0 key generate-node-key --file /var/lib/duniter/node.key`
- If you have write access errors run in docker-compose.yml folder : `chmod o+rwX -R .`
- `docker-compose up -d` to start your node
......
......@@ -8,8 +8,8 @@
[docker/compose/gdev-validator.docker-compose.yml](https://git.duniter.org/nodes/rust/duniter-v2s/-/blob/master/docker/compose/gdev-validator.docker-compose.yml)
- Create a `.env` file that define environment variables `SERVER_DOMAIN`, `PEER_ID` and `VALIDATOR_PEER_ID`:
- `SERVER_DOMAIN`: a domain name that point on your server
- `PEER_ID`: Your rpc node peer id, shoud be generated with this command: `docker run --rm -it --entrypoint -v $PWD:/var/lib/duniter/ duniter duniter/duniter-v2s:v0.1.0 key generate-node-key --file /var/lib/duniter/rpc-node.key`
- `VALIDATOR_PEER_ID`: Your validator node peer id, shoud be generated with this command: `docker run --rm -it --entrypoint -v $PWD:/var/lib/duniter/ duniter duniter/duniter-v2s:v0.1.0 key generate-node-key --file /var/lib/duniter/validator-node.key`
- `PEER_ID`: Your rpc node peer id, shoud be generated with this command: `docker run --rm -it --entrypoint -v $PWD:/var/lib/duniter/ duniter duniter/duniter-v2s:v0.2.0 key generate-node-key --file /var/lib/duniter/rpc-node.key`
- `VALIDATOR_PEER_ID`: Your validator node peer id, shoud be generated with this command: `docker run --rm -it --entrypoint -v $PWD:/var/lib/duniter/ duniter duniter/duniter-v2s:v0.2.0 key generate-node-key --file /var/lib/duniter/validator-node.key`
Note: duniter-rpc PEER_ID and duniter-validator PEER_ID isn't the same.
- If you have write access errors run in docker-compose.yml folder : `chmod o+rwX -R .`
- `docker-compose up -d` to start your node
......
......@@ -15,12 +15,13 @@ clap = { version = "3.0", features = ["derive"] }
ctrlc = "3.2.2"
cucumber = "0.11"
env_logger = "0.9.0"
hex = "0.4"
notify = "4.0"
parity-scale-codec = "3.1.5"
portpicker = "0.1.1"
serde_json = "1.0.64"
sp-keyring = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.23" }
subxt = { git = 'https://github.com/duniter/subxt.git', branch = 'duniter-substrate-v0.9.23' }
sp-keyring = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.26" }
subxt = { git = 'https://github.com/duniter/subxt.git', branch = 'duniter-substrate-v0.9.26' }
tokio = { version = "1.15.0", features = ["macros"] }
[[test]]
......
Feature: Oneshot account
Scenario: Simple oneshot consumption
When alice sends 7 ĞD to oneshot dave
Then alice should have 3 ĞD
Then dave should have oneshot 7 ĞD
When oneshot dave consumes into account bob
Then dave should have oneshot 0 ĞD
Then bob should have 1699 cĞD
Then bob should have oneshot 0 ĞD
Scenario: Double oneshot consumption
When alice sends 7 ĞD to oneshot dave
Then alice should have 3 ĞD
Then dave should have oneshot 7 ĞD
When oneshot dave consumes 4 ĞD into account bob and the rest into oneshot charlie
Then dave should have oneshot 0 ĞD
Then bob should have 14 ĞD
Then bob should have oneshot 0 ĞD
Then charlie should have 10 ĞD
Then charlie should have oneshot 299 cĞD
{
"first_ud": 1000,
"first_ud_reeval": 100,
"genesis_parameters": {
"genesis_certs_min_received": 2,
"genesis_memberships_expire_on": 100000,
"genesis_smith_certs_min_received": 2,
"genesis_smith_memberships_expire_on": 100000
},
"identities": {
"Alice": {
"balance": 1000,
......
{
"first_ud": 1000,
"first_ud_reeval": 100,
"genesis_parameters": {
"genesis_certs_min_received": 2,
"genesis_memberships_expire_on": 100000,
"genesis_smith_certs_min_received": 2,
"genesis_smith_memberships_expire_on": 100000
},
"identities": {
"Alice": {
"balance": 1000,
......
......@@ -14,30 +14,27 @@
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use super::node_runtime::runtime_types::gdev_runtime;
use super::node_runtime::runtime_types::pallet_balances;
use super::gdev;
use super::gdev::runtime_types::pallet_balances;
use super::*;
use sp_keyring::AccountKeyring;
use subxt::{sp_runtime::MultiAddress, PairSigner};
use subxt::{ext::sp_runtime::MultiAddress, tx::PairSigner};
pub async fn set_balance(
api: &Api,
client: &Client,
who: AccountKeyring,
amount: u64,
) -> Result<()> {
pub async fn set_balance(client: &Client, who: AccountKeyring, amount: u64) -> Result<()> {
let _events = create_block_with_extrinsic(
client,
api.tx()
.sudo()
.sudo(gdev_runtime::Call::Balances(
pallet_balances::pallet::Call::set_balance {
who: MultiAddress::Id(who.to_account_id()),
new_free: amount,
new_reserved: 0,
},
))?
client
.tx()
.create_signed(
&gdev::tx()
.sudo()
.sudo(gdev::runtime_types::gdev_runtime::Call::Balances(
pallet_balances::pallet::Call::set_balance {
who: MultiAddress::Id(who.to_account_id()),
new_free: amount,
new_reserved: 0,
},
)),
&PairSigner::new(SUDO_ACCOUNT.pair()),
BaseExtrinsicParamsBuilder::new(),
)
......@@ -49,7 +46,6 @@ pub async fn set_balance(
}
pub async fn transfer(
api: &Api,
client: &Client,
from: AccountKeyring,
amount: u64,
......@@ -60,10 +56,15 @@ pub async fn transfer(
let _events = create_block_with_extrinsic(
client,
api.tx()
.balances()
.transfer(to.clone().into(), amount)?
.create_signed(&from, BaseExtrinsicParamsBuilder::new())
client
.tx()
.create_signed(
&gdev::tx()
.universal_dividend()
.transfer_ud(to.clone().into(), amount),
&from,
BaseExtrinsicParamsBuilder::new(),
)
.await?,
)
.await?;
......@@ -71,21 +72,19 @@ pub async fn transfer(
Ok(())
}
pub async fn transfer_all(
api: &Api,
client: &Client,
from: AccountKeyring,
to: AccountKeyring,
) -> Result<()> {
pub async fn transfer_all(client: &Client, from: AccountKeyring, to: AccountKeyring) -> Result<()> {
let from = PairSigner::new(from.pair());
let to = to.to_account_id();
let _events = create_block_with_extrinsic(
client,
api.tx()
.balances()
.transfer_all(to.clone().into(), false)?
.create_signed(&from, BaseExtrinsicParamsBuilder::new())
client
.tx()
.create_signed(
&gdev::tx().balances().transfer_all(to.clone().into(), false),
&from,
BaseExtrinsicParamsBuilder::new(),
)
.await?,
)
.await?;
......@@ -94,7 +93,6 @@ pub async fn transfer_all(
}
pub async fn transfer_ud(
api: &Api,
client: &Client,
from: AccountKeyring,
amount: u64,
......@@ -105,10 +103,15 @@ pub async fn transfer_ud(
let _events = create_block_with_extrinsic(
client,
api.tx()
.universal_dividend()
.transfer_ud(to.clone().into(), amount)?
.create_signed(&from, BaseExtrinsicParamsBuilder::new())
client
.tx()
.create_signed(
&gdev::tx()
.universal_dividend()
.transfer_ud(to.clone().into(), amount),
&from,
BaseExtrinsicParamsBuilder::new(),
)
.await?,
)
.await?;
......
......@@ -14,41 +14,37 @@
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use super::node_runtime::runtime_types::gdev_runtime;
use super::node_runtime::runtime_types::pallet_certification;
use super::gdev;
use super::gdev::runtime_types::pallet_certification;
use super::*;
use sp_keyring::AccountKeyring;
use subxt::{sp_runtime::MultiAddress, PairSigner};
use subxt::{ext::sp_runtime::MultiAddress, tx::PairSigner};
pub async fn certify(
api: &Api,
client: &Client,
from: AccountKeyring,
to: AccountKeyring,
) -> Result<()> {
pub async fn certify(client: &Client, from: AccountKeyring, to: AccountKeyring) -> Result<()> {
let signer = PairSigner::new(from.pair());
let from = from.to_account_id();
let to = to.to_account_id();
let issuer_index = api
let issuer_index = client
.storage()
.identity()
.identity_index_of(&from, None)
.fetch(&gdev::storage().identity().identity_index_of(&from), None)
.await?
.unwrap();
let receiver_index = api
let receiver_index = client
.storage()
.identity()
.identity_index_of(&to, None)
.fetch(&gdev::storage().identity().identity_index_of(&to), None)
.await?
.unwrap();
let _events = create_block_with_extrinsic(
client,
api.tx()
.cert()
.add_cert(issuer_index, receiver_index)?
.create_signed(&signer, BaseExtrinsicParamsBuilder::new())
client
.tx()
.create_signed(
&gdev::tx().cert().add_cert(issuer_index, receiver_index),
&signer,
BaseExtrinsicParamsBuilder::new(),
)
.await?,
)
.await?;
......
......@@ -18,9 +18,10 @@
pub mod balances;
pub mod cert;
pub mod oneshot;
#[subxt::subxt(runtime_metadata_path = "../resources/metadata.scale")]
pub mod node_runtime {}
pub mod gdev {}
use anyhow::anyhow;
use parity_scale_codec::Encode;
......@@ -30,23 +31,29 @@ use std::io::prelude::*;
use std::path::PathBuf;
use std::process::Command;
use std::str::FromStr;
use subxt::ext::{sp_core, sp_runtime};
use subxt::rpc::{rpc_params, ClientT, SubscriptionClientT};
use subxt::{extrinsic::BaseExtrinsicParamsBuilder, ClientBuilder, DefaultConfig};
use subxt::tx::BaseExtrinsicParamsBuilder;
pub type Api = node_runtime::RuntimeApi<DefaultConfig, BaseExtrinsicParams<DefaultConfig>>;
type BaseExtrinsicParams<T> = subxt::extrinsic::BaseExtrinsicParams<T, Tip>;
pub type Client = subxt::Client<DefaultConfig>;
pub type Event = node_runtime::Event;
pub type Client = subxt::OnlineClient<GdevConfig>;
pub type Event = gdev::Event;
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
pub type SignedSubmittableExtrinsic<'client> = subxt::SignedSubmittableExtrinsic<
'client,
DefaultConfig,
BaseExtrinsicParams<DefaultConfig>,
node_runtime::DispatchError,
Event,
>;
pub type TransactionProgress<'client> =
subxt::TransactionProgress<'client, DefaultConfig, node_runtime::DispatchError, Event>;
pub type SignedSubmittableExtrinsic = subxt::tx::SignedSubmittableExtrinsic<GdevConfig, Client>;
pub type TxProgress = subxt::tx::TxProgress<GdevConfig, Client>;
pub enum GdevConfig {}
impl subxt::config::Config for GdevConfig {
type Index = u32;
type BlockNumber = u32;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = sp_runtime::AccountId32;
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header = sp_runtime::generic::Header<Self::BlockNumber, sp_runtime::traits::BlakeTwo256>;
type Signature = sp_runtime::MultiSignature;
type Extrinsic = sp_runtime::OpaqueExtrinsic;
type ExtrinsicParams = subxt::tx::BaseExtrinsicParams<Self, Tip>;
}
#[derive(Copy, Clone, Debug, Default, Encode)]
pub struct Tip {
......@@ -84,7 +91,7 @@ struct FullNode {
ws_port: u16,
}
pub async fn spawn_node(maybe_genesis_conf_file: Option<PathBuf>) -> (Api, Client, Process) {
pub async fn spawn_node(maybe_genesis_conf_file: Option<PathBuf>) -> (Client, Process) {
println!("maybe_genesis_conf_file={:?}", maybe_genesis_conf_file);
let duniter_binary_path = std::env::var("DUNITER_BINARY_PATH").unwrap_or_else(|_| {
if std::path::Path::new(DUNITER_DOCKER_PATH).exists() {
......@@ -103,14 +110,11 @@ pub async fn spawn_node(maybe_genesis_conf_file: Option<PathBuf>) -> (Api, Clien
&duniter_binary_path,
maybe_genesis_conf_file,
);
let client = ClientBuilder::new()
.set_url(format!("ws://127.0.0.1:{}", ws_port))
.build()
let client = Client::from_url(format!("ws://127.0.0.1:{}", ws_port))
.await
.expect("fail to connect to node");
let api = client.clone().to_runtime_api::<Api>();
(api, client, process)
(client, process)
}
pub async fn create_empty_block(client: &Client) -> Result<()> {
......@@ -126,14 +130,10 @@ pub async fn create_empty_block(client: &Client) -> Result<()> {
pub async fn create_block_with_extrinsic(
client: &Client,
extrinsic: SignedSubmittableExtrinsic<'_>,
) -> Result<subxt::TransactionEvents<DefaultConfig, Event>> {
/*// Get a hash of the extrinsic (we'll need this later).
use subxt::sp_runtime::traits::Hash as _;
let ext_hash = <DefaultConfig as subxt::Config>::Hashing::hash_of(&encoded_extrinsic);
// Submit and watch for transaction progress.
let sub = client.rpc().submit_extrinsic(encoded_extrinsic).await?;
let watcher = TransactionProgress::new(sub, client, ext_hash);*/
extrinsic: SignedSubmittableExtrinsic,
) -> Result<subxt::tx::TxEvents<GdevConfig>> {
//println!("extrinsic encoded: {}", hex::encode(extrinsic.encoded()));
let watcher = extrinsic.submit_and_watch().await?;
// Create a non-empty block
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use super::gdev;
use super::gdev::runtime_types::pallet_balances;
use super::gdev::runtime_types::pallet_oneshot_account;
use super::*;
use sp_keyring::AccountKeyring;
use subxt::{
ext::sp_runtime::{AccountId32, MultiAddress},
tx::PairSigner,
};
pub enum Account {
Normal(AccountKeyring),
Oneshot(AccountKeyring),
}
impl Account {
fn to_account_id(
&self,
) -> pallet_oneshot_account::types::Account<MultiAddress<AccountId32, ()>> {
match self {
Account::Normal(account) => {
pallet_oneshot_account::types::Account::Normal(account.to_account_id().into())
}
Account::Oneshot(account) => {
pallet_oneshot_account::types::Account::Oneshot(account.to_account_id().into())
}
}
}
}
pub async fn create_oneshot_account(
client: &Client,
from: AccountKeyring,
amount: u64,
to: AccountKeyring,
) -> Result<()> {
let from = PairSigner::new(from.pair());
let to = to.to_account_id();
let _events = create_block_with_extrinsic(
client,
client
.tx()
.create_signed(
&gdev::tx()
.oneshot_account()
.create_oneshot_account(to.into(), amount),
&from,
BaseExtrinsicParamsBuilder::new(),
)
.await?,
)
.await?;
Ok(())
}
pub async fn consume_oneshot_account(
client: &Client,
from: AccountKeyring,
to: Account,
) -> Result<()> {
let from = PairSigner::new(from.pair());
let to = to.to_account_id();
let _events = create_block_with_extrinsic(
client,
client
.tx()
.create_signed(
&gdev::tx().oneshot_account().consume_oneshot_account(0, to),
&from,
BaseExtrinsicParamsBuilder::new(),
)
.await?,
)
.await?;
Ok(())
}
#[allow(clippy::too_many_arguments)]
pub async fn consume_oneshot_account_with_remaining(
client: &Client,
from: AccountKeyring,
amount: u64,
to: Account,
remaining_to: Account,
) -> Result<()> {
let from = PairSigner::new(from.pair());
let to = to.to_account_id();
let remaining_to = remaining_to.to_account_id();
let _events = create_block_with_extrinsic(
client,
client
.tx()
.create_signed(
&gdev::tx()
.oneshot_account()
.consume_oneshot_account_with_remaining(0, to, remaining_to, amount),
&from,
BaseExtrinsicParamsBuilder::new(),
)
.await?,
)
.await?;
Ok(())
}
......@@ -53,13 +53,6 @@ impl DuniterWorld {
self.ignore_errors = ignore_errors;
}
// Read methods
fn api(&self) -> &Api {
if let Some(ref inner) = self.inner {
&inner.api
} else {
panic!("uninit")
}
}
fn client(&self) -> &Client {
if let Some(ref inner) = self.inner {
&inner.client
......@@ -70,6 +63,39 @@ impl DuniterWorld {
fn ignore_errors(&self) -> bool {
self.ignore_errors
}
// Read storage entry on last block
fn read<'a, Address>(
&self,
address: &'a Address,
) -> impl std::future::Future<
Output = std::result::Result<
Option<<Address::Target as subxt::metadata::DecodeWithMetadata>::Target>,
subxt::error::Error,
>,
> + 'a
where
Address: subxt::storage::StorageAddress<IsFetchable = subxt::storage::address::Yes> + 'a,
{
self.client().storage().fetch(address, None)
}
// Read storage entry with default value (on last block)
fn read_or_default<'a, Address>(
&self,
address: &'a Address,
) -> impl std::future::Future<
Output = std::result::Result<
<Address::Target as subxt::metadata::DecodeWithMetadata>::Target,
subxt::error::Error,
>,
> + 'a
where
Address: subxt::storage::StorageAddress<
IsFetchable = subxt::storage::address::Yes,
IsDefaultable = subxt::storage::address::Yes,
> + 'a,
{
self.client().storage().fetch_or_default(address, None)
}
}
impl std::fmt::Debug for DuniterWorld {
......@@ -92,19 +118,14 @@ impl World for DuniterWorld {
}
struct DuniterWorldInner {
api: Api,
client: Client,
process: Process,
}
impl DuniterWorldInner {
async fn new(maybe_genesis_conf_file: Option<PathBuf>) -> Self {
let (api, client, process) = spawn_node(maybe_genesis_conf_file).await;
DuniterWorldInner {
api,
client,
process,
}
let (client, process) = spawn_node(maybe_genesis_conf_file).await;
DuniterWorldInner { client, process }
}
fn kill(&mut self) {
self.process.kill();
......@@ -131,16 +152,14 @@ async fn who_have(world: &mut DuniterWorld, who: String, amount: u64, unit: Stri
if is_ud {
let current_ud_amount = world
.api()
.storage()
.universal_dividend()
.current_ud(None)
.await?;
.read(&gdev::storage().universal_dividend().current_ud())
.await?
.unwrap_or_default();
amount = (amount * current_ud_amount) / 1_000;
}
// Create {amount} ĞD for {who}
common::balances::set_balance(world.api(), world.client(), who, amount).await?;
common::balances::set_balance(world.client(), who, amount).await?;
Ok(())
}
......@@ -155,7 +174,7 @@ async fn n_blocks_later(world: &mut DuniterWorld, n: usize) -> Result<()> {
Ok(())
}
#[when(regex = r"([a-zA-Z]+) sends? (\d+) (ĞD|cĞD|UD|mUD) to ([a-zA-Z]+)")]
#[when(regex = r"([a-zA-Z]+) sends? (\d+) (ĞD|cĞD|UD|mUD) to ([a-zA-Z]+)$")]
async fn transfer(
world: &mut DuniterWorld,
from: String,
......@@ -169,9 +188,9 @@ async fn transfer(
let (amount, is_ud) = parse_amount(amount, &unit);
let res = if is_ud {
common::balances::transfer_ud(world.api(), world.client(), from, amount, to).await
common::balances::transfer_ud(world.client(), from, amount, to).await
} else {
common::balances::transfer(world.api(), world.client(), from, amount, to).await
common::balances::transfer(world.client(), from, amount, to).await
};
if world.ignore_errors() {
......@@ -181,13 +200,92 @@ async fn transfer(
}
}
#[when(regex = r"([a-zA-Z]+) sends? (\d+) (ĞD|cĞD) to oneshot ([a-zA-Z]+)")]
async fn create_oneshot_account(
world: &mut DuniterWorld,
from: String,
amount: u64,
unit: String,
to: String,
) -> Result<()> {
// Parse inputs
let from = AccountKeyring::from_str(&from).expect("unknown from");
let to = AccountKeyring::from_str(&to).expect("unknown to");
let (amount, is_ud) = parse_amount(amount, &unit);
assert!(!is_ud);
common::oneshot::create_oneshot_account(world.client(), from, amount, to).await
}
#[when(regex = r"oneshot ([a-zA-Z]+) consumes? into (oneshot|account) ([a-zA-Z]+)")]
async fn consume_oneshot_account(
world: &mut DuniterWorld,
from: String,
is_dest_oneshot: String,
to: String,
) -> Result<()> {
// Parse inputs
let from = AccountKeyring::from_str(&from).expect("unknown from");
let to = AccountKeyring::from_str(&to).expect("unknown to");
let to = match is_dest_oneshot.as_str() {
"oneshot" => common::oneshot::Account::Oneshot(to),
"account" => common::oneshot::Account::Normal(to),
_ => unreachable!(),
};
common::oneshot::consume_oneshot_account(world.client(), from, to).await
}
#[when(
regex = r"oneshot ([a-zA-Z]+) consumes? (\d+) (ĞD|cĞD) into (oneshot|account) ([a-zA-Z]+) and the rest into (oneshot|account) ([a-zA-Z]+)"
)]
#[allow(clippy::too_many_arguments)]
async fn consume_oneshot_account_with_remaining(
world: &mut DuniterWorld,
from: String,
amount: u64,
unit: String,
is_dest_oneshot: String,
to: String,
is_remaining_to_oneshot: String,
remaining_to: String,
) -> Result<()> {
// Parse inputs
let from = AccountKeyring::from_str(&from).expect("unknown from");
let to = AccountKeyring::from_str(&to).expect("unknown to");
let remaining_to = AccountKeyring::from_str(&remaining_to).expect("unknown remaining_to");
let to = match is_dest_oneshot.as_str() {
"oneshot" => common::oneshot::Account::Oneshot(to),
"account" => common::oneshot::Account::Normal(to),
_ => unreachable!(),
};
let remaining_to = match is_remaining_to_oneshot.as_str() {
"oneshot" => common::oneshot::Account::Oneshot(remaining_to),
"account" => common::oneshot::Account::Normal(remaining_to),
_ => unreachable!(),
};
let (amount, is_ud) = parse_amount(amount, &unit);
assert!(!is_ud);
common::oneshot::consume_oneshot_account_with_remaining(
world.client(),
from,
amount,
to,
remaining_to,
)
.await
}
#[when(regex = r"([a-zA-Z]+) sends? all (?:his|her) (?:ĞDs?|DUs?|UDs?) to ([a-zA-Z]+)")]
async fn send_all_to(world: &mut DuniterWorld, from: String, to: String) -> Result<()> {
// Parse inputs
let from = AccountKeyring::from_str(&from).expect("unknown from");
let to = AccountKeyring::from_str(&to).expect("unknown to");
common::balances::transfer_all(world.api(), world.client(), from, to).await
common::balances::transfer_all(world.client(), from, to).await
}
#[when(regex = r"([a-zA-Z]+) certifies ([a-zA-Z]+)")]
......@@ -196,7 +294,7 @@ async fn certifies(world: &mut DuniterWorld, from: String, to: String) -> Result
let from = AccountKeyring::from_str(&from).expect("unknown from");
let to = AccountKeyring::from_str(&to).expect("unknown to");
common::cert::certify(world.api(), world.client(), from, to).await
common::cert::certify(world.client(), from, to).await
}
// ===== then ====
......@@ -214,11 +312,33 @@ async fn should_have(
.to_account_id();
let (amount, _is_ud) = parse_amount(amount, &unit);
let who_account = world.api().storage().system().account(&who, None).await?;
let who_account = world
.read_or_default(&gdev::storage().system().account(&who))
.await?;
assert_eq!(who_account.data.free, amount);
Ok(())
}
#[then(regex = r"([a-zA-Z]+) should have oneshot (\d+) (ĞD|cĞD)")]
async fn should_have_oneshot(
world: &mut DuniterWorld,
who: String,
amount: u64,
unit: String,
) -> Result<()> {
// Parse inputs
let who = AccountKeyring::from_str(&who)
.expect("unknown to")
.to_account_id();
let (amount, _is_ud) = parse_amount(amount, &unit);
let oneshot_amount = world
.read(&gdev::storage().oneshot_account().oneshot_accounts(&who))
.await?;
assert_eq!(oneshot_amount.unwrap_or(0), amount);
Ok(())
}
#[then(regex = r"Current UD amount should be (\d+).(\d+)")]
async fn current_ud_amount_should_be(
world: &mut DuniterWorld,
......@@ -227,10 +347,7 @@ async fn current_ud_amount_should_be(
) -> Result<()> {
let expected = (amount * 100) + cents;
let actual = world
.api()
.storage()
.universal_dividend()
.current_ud(None)
.read_or_default(&gdev::storage().universal_dividend().current_ud())
.await?;
assert_eq!(actual, expected);
Ok(())
......@@ -240,10 +357,7 @@ async fn current_ud_amount_should_be(
async fn monetary_mass_should_be(world: &mut DuniterWorld, amount: u64, cents: u64) -> Result<()> {
let expected = (amount * 100) + cents;
let actual = world
.api()
.storage()
.universal_dividend()
.monetary_mass(None)
.read_or_default(&gdev::storage().universal_dividend().monetary_mass())
.await?;
assert_eq!(actual, expected);
Ok(())
......@@ -264,25 +378,24 @@ async fn should_be_certified_by(
.to_account_id();
let issuer_index = world
.api()
.storage()
.identity()
.identity_index_of(&issuer_account, None)
.read(
&gdev::storage()
.identity()
.identity_index_of(&issuer_account),
)
.await?
.unwrap();
let receiver_index = world
.api()
.storage()
.identity()
.identity_index_of(&receiver_account, None)
.read(
&gdev::storage()
.identity()
.identity_index_of(&receiver_account),
)
.await?
.unwrap();
let issuers = world
.api()
.storage()
.cert()
.certs_by_receiver(&receiver_index, None)
.read_or_default(&gdev::storage().cert().certs_by_receiver(&receiver_index))
.await?;
match issuers.binary_search_by(|(issuer_, _)| issuer_index.cmp(issuer_)) {
......
......@@ -12,6 +12,6 @@ version = '3.0.0'
anyhow = "1.0"
hex-literal = "0.3"
parity-scale-codec = "3.1.5"
sp-core = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23' }
subxt = { git = 'https://github.com/duniter/subxt', branch = 'duniter-substrate-v0.9.23' }
sp-core = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
subxt = { git = 'https://github.com/duniter/subxt', branch = 'duniter-substrate-v0.9.26' }
tokio = { version = "1.15.0", features = ["macros"] }
......@@ -15,22 +15,20 @@
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#[subxt::subxt(runtime_metadata_path = "../resources/metadata.scale")]
pub mod gdev_runtime {}
pub mod gdev {}
use hex_literal::hex;
use sp_core::crypto::AccountId32;
use sp_core::{blake2_128, ByteArray, H256};
use std::collections::HashMap;
use subxt::{extrinsic::PlainTip, ClientBuilder, DefaultConfig};
use subxt::config::SubstrateConfig as GdevConfig;
const DEFAULT_ENDPOINT: &str = "wss://gdev.librelois.fr:443/ws";
const TREASURY_ACCOUNT_ID: [u8; 32] =
hex!("6d6f646c70792f74727372790000000000000000000000000000000000000000");
type Api = gdev_runtime::RuntimeApi<DefaultConfig, BaseExtrinsicParams<DefaultConfig>>;
type BaseExtrinsicParams<T> = subxt::extrinsic::BaseExtrinsicParams<T, PlainTip>;
type Client = subxt::Client<DefaultConfig>;
type Client = subxt::OnlineClient<GdevConfig>;
// define gdev basic types
type Balance = u64;
......@@ -38,18 +36,15 @@ type BlockNumber = u32;
type Index = u32;
// Define gdev types
type AccountInfo = gdev_runtime::runtime_types::frame_system::AccountInfo<
type AccountInfo = gdev::runtime_types::frame_system::AccountInfo<
Index,
gdev_runtime::runtime_types::pallet_duniter_account::types::AccountData<Balance>,
gdev::runtime_types::pallet_duniter_account::types::AccountData<Balance>,
>;
type IdtyData = gdev_runtime::runtime_types::common_runtime::entities::IdtyData;
type IdtyData = gdev::runtime_types::common_runtime::entities::IdtyData;
type IdtyIndex = u32;
type IdtyValue = gdev_runtime::runtime_types::pallet_identity::types::IdtyValue<
BlockNumber,
AccountId32,
IdtyData,
>;
use gdev_runtime::runtime_types::pallet_identity::types::IdtyStatus;
type IdtyValue =
gdev::runtime_types::pallet_identity::types::IdtyValue<BlockNumber, AccountId32, IdtyData>;
use gdev::runtime_types::pallet_identity::types::IdtyStatus;
struct Storage {
accounts: HashMap<AccountId32, AccountInfo>,
......@@ -61,10 +56,7 @@ struct Storage {
async fn main() -> anyhow::Result<()> {
let ws_rpc_endpoint =
std::env::var("WS_RPC_ENDPOINT").unwrap_or_else(|_| DEFAULT_ENDPOINT.to_owned());
let client: Client = ClientBuilder::new()
.set_url(ws_rpc_endpoint)
.set_page_size(100)
.build()
let client = Client::from_url(ws_rpc_endpoint)
.await
.expect("fail to connect to node");
......@@ -81,17 +73,17 @@ async fn main() -> anyhow::Result<()> {
}
async fn sanity_tests_at(client: Client, maybe_block_hash: Option<H256>) -> anyhow::Result<()> {
// Get API
let api = client.clone().to_runtime_api::<Api>();
// ===== Collect storage ===== //
// Collect accounts
let mut accounts = HashMap::new();
let mut account_iter = api
let mut account_iter = client
.storage()
.system()
.account_iter(maybe_block_hash)
.iter(
gdev::storage().system().account_root(),
100,
maybe_block_hash,
)
.await?;
while let Some((key, account_info)) = account_iter.next().await? {
let mut account_id_bytes = [0u8; 32];
......@@ -102,10 +94,13 @@ async fn sanity_tests_at(client: Client, maybe_block_hash: Option<H256>) -> anyh
// Collect identities
let mut identities = HashMap::new();
let mut idty_iter = api
let mut idty_iter = client
.storage()
.identity()
.identities_iter(maybe_block_hash)
.iter(
gdev::storage().identity().identities_root(),
100,
maybe_block_hash,
)
.await?;
while let Some((key, idty_value)) = idty_iter.next().await? {
let mut idty_index_bytes = [0u8; 4];
......@@ -116,10 +111,13 @@ async fn sanity_tests_at(client: Client, maybe_block_hash: Option<H256>) -> anyh
// Collect identity_index_of
let mut identity_index_of = HashMap::new();
let mut idty_index_of_iter = api
let mut idty_index_of_iter = client
.storage()
.identity()
.identity_index_of_iter(maybe_block_hash)
.iter(
gdev::storage().identity().identity_index_of_root(),
100,
maybe_block_hash,
)
.await?;
while let Some((key, idty_index)) = idty_index_of_iter.next().await? {
let mut blake2_128_bytes = [0u8; 16];
......
This diff is collapsed.
......@@ -57,8 +57,7 @@ where
fn clique_wot(
initial_identities_len: usize,
cert_validity_period: common_runtime::BlockNumber,
) -> BTreeMap<IdtyIndex, BTreeMap<IdtyIndex, common_runtime::BlockNumber>> {
) -> BTreeMap<IdtyIndex, BTreeMap<IdtyIndex, Option<common_runtime::BlockNumber>>> {
let mut certs_by_issuer = BTreeMap::new();
for i in 1..=initial_identities_len {
certs_by_issuer.insert(
......@@ -66,7 +65,7 @@ fn clique_wot(
(1..=initial_identities_len)
.filter_map(|j| {
if i != j {
Some((j as IdtyIndex, cert_validity_period))
Some((j as IdtyIndex, None))
} else {
None
}
......