├── .github ├── dependabot.yml └── workflows │ ├── conformance.yml │ ├── integration.yml │ └── nix-flake.yml ├── .gitignore ├── .gitmodules ├── .nix ├── gossamer │ ├── config_path.patch │ └── default.nix ├── kagome │ ├── default.nix │ ├── dependencies.patch │ ├── dependencies │ │ ├── backward-cpp.nix │ │ ├── binaryen.nix │ │ ├── boost-di.nix │ │ ├── cpp-libp2p │ │ │ ├── default.nix │ │ │ ├── dependencies.patch │ │ │ └── test-cares.patch │ │ ├── default.nix │ │ ├── erasure-coding-crust.nix │ │ ├── fmt.nix │ │ ├── googletest.nix │ │ ├── jsonrpc-lean.nix │ │ ├── libsecp256k1.nix │ │ ├── microsoft-gsl.nix │ │ ├── prometheus-cpp.nix │ │ ├── rapidjson.nix │ │ ├── rocksdb.nix │ │ ├── scale-codec-cpp.nix │ │ ├── schnorrkel-crust.nix │ │ ├── soralog │ │ │ ├── default.nix │ │ │ └── yaml-cpp.patch │ │ ├── sqlite-modern-cpp │ │ │ ├── default.nix │ │ │ └── package_name.patch │ │ ├── tsl-hat-trie.nix │ │ ├── wavm.nix │ │ └── xxhash.nix │ └── zstd.patch ├── packages.nix ├── substrate │ ├── default.nix │ └── env.nix └── testsuite.nix ├── LICENSE ├── Makefile ├── README.md ├── adapters ├── gossamer │ ├── .gitignore │ ├── Makefile │ ├── default.nix │ ├── go.mod │ ├── go.sum │ ├── host_api │ │ ├── allocator.go │ │ ├── child_storage.go │ │ ├── crypto.go │ │ ├── errors.go │ │ ├── hashing.go │ │ ├── host_api.go │ │ ├── storage.go │ │ └── trie.go │ ├── main.go │ ├── scale_codec.go │ ├── shell.nix │ ├── state_trie.go │ └── util.go ├── kagome │ ├── .clang-format │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile │ ├── cmake │ │ ├── HunterConfig.cmake │ │ ├── HunterGate.cmake │ │ ├── HunterPasswords.cmake │ │ └── Toolchain.cmake │ ├── default.nix │ ├── shell.nix │ └── src │ │ ├── assert.cpp │ │ ├── assert.hpp │ │ ├── host_api.cpp │ │ ├── host_api.hpp │ │ ├── host_api │ │ ├── allocator.cpp │ │ ├── allocator.hpp │ │ ├── child_storage.cpp │ │ ├── child_storage.hpp │ │ ├── crypto.cpp │ │ ├── crypto.hpp │ │ ├── hashing.cpp │ │ ├── hashing.hpp │ │ ├── helpers.cpp │ │ ├── helpers.hpp │ │ ├── storage.cpp │ │ ├── storage.hpp │ │ ├── trie.cpp │ │ └── trie.hpp │ │ ├── main.cpp │ │ ├── scale_codec.cpp │ │ ├── scale_codec.hpp │ │ ├── state_trie.cpp │ │ ├── state_trie.hpp │ │ └── subcommand.hpp └── substrate │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Makefile │ ├── default.nix │ ├── shell.nix │ └── src │ ├── host_api │ ├── allocator.rs │ ├── child_storage.rs │ ├── crypto.rs │ ├── hashing.rs │ ├── mod.rs │ ├── offchain.rs │ ├── storage.rs │ ├── trie.rs │ └── utils.rs │ ├── main.rs │ ├── scale_codec.rs │ └── state_trie.rs ├── fixtures ├── genesis-default │ └── include.jl ├── genesis-legacy │ └── include.jl ├── host-api │ ├── HostApiFunctions.jl │ ├── HostApiInputs.jl │ ├── HostApiOutputs.jl │ └── include.jl ├── scale-codec │ └── include.jl └── state-trie │ ├── 10000_node.yaml │ ├── 1c1.yaml │ ├── hex_1c1.yaml │ ├── hex_limit.yaml │ ├── hex_long.yaml │ ├── include.jl │ ├── pk_branch.yaml │ ├── pk_branch2.yaml │ ├── random_state_80.yaml │ └── scv.yaml ├── flake.lock ├── flake.nix ├── helpers ├── AdapterFixture.jl ├── HostFixture.jl ├── SpecificationTestsuite.jl └── StringHelpers.jl ├── hosts └── Makefile ├── runtests.jl ├── runtimes ├── hostapi │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Makefile │ ├── build.rs │ ├── default.nix │ ├── shell.nix │ └── src │ │ └── lib.rs └── tester │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Makefile │ ├── default.nix │ ├── gossamer.config.toml │ ├── keystore │ ├── babed43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d │ ├── gran88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee │ └── lp2p48453469c62f4885373099421a7365520b5ffb0d93726c124166be4b81d852e6 │ ├── runtime │ ├── Cargo.toml │ ├── build.rs │ └── src │ │ └── lib.rs │ ├── shell.nix │ └── src │ └── main.rs └── rust-toolchain.toml /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | # Submodules (hosts and adapters) 5 | 6 | - package-ecosystem: "gitsubmodule" 7 | directory: "/" 8 | schedule: 9 | interval: "weekly" 10 | commit-message: 11 | prefix: "submodule:" 12 | 13 | # Runtimes (not synced with submodules) 14 | 15 | - package-ecosystem: "cargo" 16 | directory: "/runtimes/hostapi" 17 | schedule: 18 | interval: "weekly" 19 | commit-message: 20 | prefix: "hostapi-rt:" 21 | 22 | # GitHub Actions 23 | 24 | - package-ecosystem: "github-actions" 25 | directory: "/" 26 | schedule: 27 | interval: "weekly" 28 | commit-message: 29 | prefix: "ci:" 30 | -------------------------------------------------------------------------------- /.github/workflows/nix-flake.yml: -------------------------------------------------------------------------------- 1 | name: Nix Flake Integration 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | package: 15 | - gossamer-adapter 16 | - kagome-adapter 17 | - substrate-adapter 18 | - gossamer-host 19 | - kagome-host 20 | - substrate-host 21 | - hostapi-runtime 22 | - tester-runtime 23 | name: "[build] ${{ matrix.package }}" 24 | runs-on: ubuntu-20.04 25 | steps: 26 | - name: Checkout repository 27 | uses: actions/checkout@v3 28 | with: 29 | submodules: true 30 | fetch-depth: 0 31 | - uses: cachix/install-nix-action@v19 32 | - uses: cachix/cachix-action@v12 33 | with: 34 | name: polkadot-tests 35 | authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' 36 | - name: Build ${{ matrix.package }} 37 | run: | 38 | nix flake lock --update-input substrate-submodule --update-input kagome-submodule --update-input gossamer-submodule 39 | nix build .#${{ matrix.package }} 40 | 41 | check: 42 | needs: [ build ] 43 | name: "[test] flake check" 44 | runs-on: ubuntu-20.04 45 | steps: 46 | - name: Checkout repository 47 | uses: actions/checkout@v3 48 | with: 49 | submodules: true 50 | fetch-depth: 0 51 | - uses: cachix/install-nix-action@v19 52 | - uses: cachix/cachix-action@v12 53 | with: 54 | name: polkadot-tests 55 | authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' 56 | - name: Run flake check 57 | run: | 58 | nix flake lock --update-input substrate-submodule --update-input kagome-submodule --update-input gossamer-submodule 59 | nix flake check 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /lib/ 3 | .vscode/** 4 | .envrc 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "hosts/kagome"] 2 | path = hosts/kagome 3 | url = https://github.com/soramitsu/kagome.git 4 | [submodule "hosts/gossamer"] 5 | path = hosts/gossamer 6 | url = https://github.com/ChainSafe/gossamer.git 7 | [submodule "hosts/substrate"] 8 | path = hosts/substrate 9 | url = https://github.com/paritytech/polkadot.git 10 | -------------------------------------------------------------------------------- /.nix/gossamer/config_path.patch: -------------------------------------------------------------------------------- 1 | diff --git a/chain/dev/config.toml b/chain/dev/config.toml 2 | index 434e79f5..8ae7aeac 100644 3 | --- a/chain/dev/config.toml 4 | +++ b/chain/dev/config.toml 5 | @@ -14,9 +14,6 @@ grandpa = "" 6 | sync = "" 7 | digest = "" 8 | 9 | -[init] 10 | -genesis = "./chain/dev/genesis.json" 11 | - 12 | [account] 13 | key = "" 14 | unlock = "" 15 | diff --git a/chain/dev/defaults.go b/chain/dev/defaults.go 16 | index 88193c2d..636a83b3 100644 17 | --- a/chain/dev/defaults.go 18 | +++ b/chain/dev/defaults.go 19 | @@ -18,7 +18,7 @@ 20 | // DefaultID is the chain ID 21 | DefaultID = string("dev") 22 | // DefaultConfig is the toml configuration path 23 | - DefaultConfig = string("./chain/dev/config.toml") 24 | + DefaultConfig = string("@out@/share/dev/config.toml") 25 | // DefaultBasePath is the node base directory path 26 | DefaultBasePath = string("~/.gossamer/dev") 27 | 28 | @@ -39,7 +39,7 @@ 29 | // InitConfig 30 | 31 | // DefaultGenesis is the default genesis configuration path 32 | - DefaultGenesis = string("./chain/dev/genesis.json") 33 | + DefaultGenesis = string("@out@/share/dev/genesis.json") 34 | 35 | // AccountConfig 36 | 37 | diff --git a/chain/gssmr/config.toml b/chain/gssmr/config.toml 38 | index 5165b96f..58c9acc6 100644 39 | --- a/chain/gssmr/config.toml 40 | +++ b/chain/gssmr/config.toml 41 | @@ -14,9 +14,6 @@ grandpa = "" 42 | sync = "" 43 | digest = "" 44 | 45 | -[init] 46 | -genesis = "./chain/gssmr/genesis.json" 47 | - 48 | [account] 49 | key = "" 50 | unlock = "" 51 | diff --git a/chain/gssmr/defaults.go b/chain/gssmr/defaults.go 52 | index 0295be7a..c42b49b6 100644 53 | --- a/chain/gssmr/defaults.go 54 | +++ b/chain/gssmr/defaults.go 55 | @@ -20,7 +20,7 @@ 56 | // DefaultID Default chain ID 57 | DefaultID = string("gssmr") 58 | // DefaultConfig Default toml configuration path 59 | - DefaultConfig = string("./chain/gssmr/config.toml") 60 | + DefaultConfig = string("@out@/share/gssmr/config.toml") 61 | // DefaultBasePath Default node base directory path 62 | DefaultBasePath = string("~/.gossamer/gssmr") 63 | 64 | @@ -41,7 +41,7 @@ 65 | // InitConfig 66 | 67 | // DefaultGenesis is the default genesis configuration path 68 | - DefaultGenesis = string("./chain/gssmr/genesis.json") 69 | + DefaultGenesis = string("@out@/share/gssmr/genesis.json") 70 | 71 | // AccountConfig 72 | 73 | diff --git a/chain/kusama/config.toml b/chain/kusama/config.toml 74 | index 865fd01f..b6ece58e 100644 75 | --- a/chain/kusama/config.toml 76 | +++ b/chain/kusama/config.toml 77 | @@ -14,9 +14,6 @@ grandpa = "" 78 | sync = "" 79 | digest = "" 80 | 81 | -[init] 82 | -genesis = "./chain/kusama/genesis.json" 83 | - 84 | [account] 85 | key = "" 86 | unlock = "" 87 | diff --git a/chain/kusama/defaults.go b/chain/kusama/defaults.go 88 | index 57183b18..b99b8209 100644 89 | --- a/chain/kusama/defaults.go 90 | +++ b/chain/kusama/defaults.go 91 | @@ -18,7 +18,7 @@ 92 | // DefaultID Default chain ID 93 | DefaultID = string("ksmcc3") 94 | // DefaultConfig Default toml configuration path 95 | - DefaultConfig = string("./chain/kusama/config.toml") 96 | + DefaultConfig = string("@out@/share/kusama/config.toml") 97 | // DefaultBasePath Default node base directory path 98 | DefaultBasePath = string("~/.gossamer/kusama") 99 | 100 | @@ -39,7 +39,7 @@ 101 | // InitConfig 102 | 103 | // DefaultGenesis is the default genesis configuration path 104 | - DefaultGenesis = string("./chain/kusama/genesis.json") 105 | + DefaultGenesis = string("@out@/share/kusama/genesis.json") 106 | 107 | // AccountConfig 108 | 109 | diff --git a/chain/polkadot/config.toml b/chain/polkadot/config.toml 110 | index 26ae4ba7..bbfb218c 100644 111 | --- a/chain/polkadot/config.toml 112 | +++ b/chain/polkadot/config.toml 113 | @@ -14,9 +14,6 @@ grandpa = "" 114 | sync = "" 115 | digest = "" 116 | 117 | -[init] 118 | -genesis = "./chain/polkadot/genesis.json" 119 | - 120 | [account] 121 | key = "" 122 | unlock = "" 123 | diff --git a/chain/polkadot/defaults.go b/chain/polkadot/defaults.go 124 | index 2a756488..1b9a3200 100644 125 | --- a/chain/polkadot/defaults.go 126 | +++ b/chain/polkadot/defaults.go 127 | @@ -18,7 +18,7 @@ 128 | // DefaultID Default chain ID 129 | DefaultID = string("polkadot") 130 | // DefaultConfig Default toml configuration path 131 | - DefaultConfig = string("./chain/polkadot/config.toml") 132 | + DefaultConfig = string("@out@/share/polkadot/config.toml") 133 | // DefaultBasePath Default node base directory path 134 | DefaultBasePath = string("~/.gossamer/polkadot") 135 | 136 | @@ -36,7 +36,7 @@ 137 | // InitConfig 138 | 139 | // DefaultGenesis is the default genesis configuration path 140 | - DefaultGenesis = string("./chain/polkadot/genesis.json") 141 | + DefaultGenesis = string("@out@/share/polkadot/genesis.json") 142 | 143 | // AccountConfig 144 | 145 | -------------------------------------------------------------------------------- /.nix/gossamer/default.nix: -------------------------------------------------------------------------------- 1 | { lib, gossamer-submodule, buildGo118Module, patchelf, glibc }: 2 | 3 | buildGo118Module rec { 4 | pname = "gossamer-host"; 5 | 6 | src = gossamer-submodule; 7 | version = gossamer-submodule.shortRev; 8 | 9 | patches = [ ./config_path.patch ]; 10 | 11 | postPatch = '' 12 | substituteAllInPlace chain/dev/defaults.go 13 | substituteAllInPlace chain/gssmr/defaults.go 14 | substituteAllInPlace chain/kusama/defaults.go 15 | substituteAllInPlace chain/polkadot/defaults.go 16 | ''; 17 | 18 | proxyVendor = true; 19 | 20 | vendorSha256 = "znCC5xkOzZzuy541MOtHK0J02eRU9zWwrKFKDpof30c="; 21 | 22 | subPackages = [ "cmd/gossamer" ]; 23 | 24 | nativeBuildInputs = [ patchelf ]; 25 | 26 | doCheck = false; # Patching default.go breaks some tests 27 | 28 | postInstall = '' 29 | mkdir $out/lib 30 | 31 | cp /build/go/pkg/mod/github.com/wasmerio/go-ext-wasm@*/wasmer/libwasmer.so $out/lib 32 | patchelf --set-rpath "$out/lib:${glibc}/lib" $out/bin/gossamer 33 | 34 | mv $out/bin/gossamer $out/bin/${pname} 35 | 36 | mkdir $out/share 37 | cp -r chain/* $out/share 38 | rm $out/share/*/*.go 39 | ''; 40 | } 41 | -------------------------------------------------------------------------------- /.nix/kagome/default.nix: -------------------------------------------------------------------------------- 1 | { kagome-submodule 2 | , stdenv 3 | , cmake 4 | , openssl 5 | , protobuf 6 | , gtest_cmake 7 | , boost172 8 | , microsoft-gsl_cmake 9 | , soralog 10 | , rocksdb_cmake 11 | , rapidjson_cmake 12 | , jsonrpc-lean 13 | , xxHash_cmake 14 | , libsecp256k1_cmake 15 | , binaryen_cmake 16 | , backward-cpp_cmake 17 | , wavm 18 | , cpp-libp2p 19 | , boost-di 20 | , erasure-coding-crust 21 | , prometheus-cpp 22 | , schnorrkel-crust 23 | , libnsl 24 | , zstd 25 | , scale-codec-cpp 26 | }: 27 | 28 | stdenv.mkDerivation rec { 29 | pname = "kagome-host"; 30 | 31 | src = kagome-submodule; 32 | version = kagome-submodule.shortRev; 33 | 34 | #sourceRoot = "source/hosts/kagome"; 35 | 36 | patches = [ 37 | ./dependencies.patch 38 | ./zstd.patch 39 | ]; 40 | 41 | nativeBuildInputs = [ 42 | cmake 43 | ]; 44 | 45 | buildInputs = [ 46 | # Working upstream dependencies 47 | protobuf 48 | 49 | # Patched upstream dependencies 50 | backward-cpp_cmake 51 | gtest_cmake 52 | 53 | # Custom packaged dependencies 54 | boost-di 55 | jsonrpc-lean 56 | ]; 57 | 58 | propagatedBuildInputs = [ 59 | boost172 60 | libnsl 61 | openssl 62 | zstd 63 | 64 | binaryen_cmake 65 | libsecp256k1_cmake 66 | microsoft-gsl_cmake 67 | rapidjson_cmake 68 | rocksdb_cmake 69 | xxHash_cmake 70 | 71 | cpp-libp2p 72 | erasure-coding-crust 73 | prometheus-cpp 74 | scale-codec-cpp 75 | schnorrkel-crust 76 | soralog 77 | wavm 78 | ]; 79 | 80 | cmakeFlags = [ "-DHUNTER_ENABLED=false" "-DTESTING=false" ]; 81 | 82 | postInstall = '' 83 | ln -s $out/bin/kagome/kagome $out/bin/${pname} 84 | ''; 85 | } 86 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies.patch: -------------------------------------------------------------------------------- 1 | diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake 2 | index 58957115..abddbb96 100644 3 | --- a/cmake/dependencies.cmake 4 | +++ b/cmake/dependencies.cmake 5 | @@ -34,7 +34,7 @@ find_package(OpenSSL REQUIRED) 6 | 7 | # https://developers.google.com/protocol-buffers/ 8 | hunter_add_package(Protobuf) 9 | -find_package(Protobuf CONFIG REQUIRED) 10 | +find_package(Protobuf REQUIRED) 11 | 12 | # http://rapidjson.org 13 | hunter_add_package(RapidJSON) 14 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/backward-cpp.nix: -------------------------------------------------------------------------------- 1 | { stdenv 2 | , fetchFromGitHub 3 | , cmake 4 | }: 5 | 6 | stdenv.mkDerivation rec { 7 | pname = "backward-cpp"; 8 | version = "1.6"; 9 | 10 | src = fetchFromGitHub { 11 | owner = "bombela"; 12 | repo = pname; 13 | rev = "v${version}"; 14 | sha256 = "2k5PjwFxgA/2XPqJrPHxgSInM61FBEcieppBx+MAUKw="; 15 | }; 16 | 17 | nativeBuildInputs = [ cmake ]; 18 | 19 | cmakeFlags = [ "-DHUNTER_ENABLED=OFF" "-DBACKWARD_TESTS=OFF" ]; 20 | } 21 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/binaryen.nix: -------------------------------------------------------------------------------- 1 | { fetchFromGitHub, binaryen }: 2 | 3 | binaryen.overrideAttrs (super: rec { 4 | name = "${super.pname}-${version}"; 5 | version = "1.38.28-p1"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "warchant"; 9 | repo = "binaryen"; 10 | rev = version; 11 | sha256 = "1x2s76klkqc6306szzm856n3w9ga18g97ah00gvcy79yk9b3ag3y"; 12 | }; 13 | 14 | patches = []; 15 | 16 | cmakeFlags = [ "-DBUILD_LLVM_DWARF=OFF" "-DBUILD_TOOLS=OFF" ]; 17 | }) 18 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/boost-di.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "boost_di"; 5 | version = "1.1.0+cmake"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "soramitsu"; 9 | repo = "soramitsu-boost-di"; 10 | rev = "a20eebb6decfba55867a6920e00443a9485f50cd"; 11 | sha256 = "eRtB/XSGTDU1n6kw4FAUr4fB6Q9xCrNF2OQE8aHEXDs="; 12 | }; 13 | 14 | nativeBuildInputs = [ cmake ]; 15 | 16 | cmakeFlags = [ 17 | # TODO: Flags just copied from hunter. Fix and run testsuite 18 | "-DBOOST_DI_OPT_BUILD_TESTS=OFF" 19 | "-DBOOST_DI_OPT_BUILD_EXAMPLES=OFF" 20 | ]; 21 | } 22 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/cpp-libp2p/default.nix: -------------------------------------------------------------------------------- 1 | { lib 2 | , stdenv 3 | , fetchFromGitHub 4 | , cmake 5 | , gtest_cmake 6 | , boost172 7 | , protobuf 8 | , openssl 9 | , microsoft-gsl_cmake 10 | , soralog 11 | , boost-di 12 | , tsl-hat-trie 13 | , sqlite-modern-cpp 14 | , c-ares 15 | , withTests ? false 16 | }: 17 | 18 | stdenv.mkDerivation rec { 19 | pname = "cpp-libp2p"; 20 | version = "0.1.8"; 21 | 22 | src = fetchFromGitHub { 23 | owner = "soramitsu"; 24 | repo = "cpp-libp2p"; 25 | rev = "v${version}"; 26 | sha256 = "1xsufDtYS7NO/KtSrUDJbbijSvy1TH2QQnC5Wh2lW/g="; 27 | }; 28 | 29 | patches = [ 30 | ./dependencies.patch 31 | ] ++ lib.optionals withTests [ 32 | ./test-cares.patch 33 | ]; 34 | 35 | nativeBuildInputs = [ 36 | cmake 37 | ]; 38 | 39 | buildInputs = [ 40 | gtest_cmake 41 | microsoft-gsl_cmake 42 | ]; 43 | 44 | propagatedBuildInputs = [ 45 | boost172 46 | openssl 47 | protobuf 48 | 49 | c-ares.cmake-config 50 | 51 | soralog 52 | boost-di 53 | sqlite-modern-cpp 54 | tsl-hat-trie 55 | ]; 56 | 57 | doCheck = withTests; 58 | 59 | cmakeFlags = [ 60 | "-DHUNTER_ENABLED=false" 61 | "-DTESTING=${lib.boolToString withTests}" 62 | "-DEXAMPLES=false" 63 | "-DEXPOSE_MOCKS=true" 64 | ]; 65 | } 66 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/cpp-libp2p/dependencies.patch: -------------------------------------------------------------------------------- 1 | diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake 2 | index e9eb5b6..bf16c6d 100644 3 | --- a/cmake/dependencies.cmake 4 | +++ b/cmake/dependencies.cmake 5 | @@ -5,7 +5,7 @@ find_package(GMock CONFIG REQUIRED) 6 | 7 | # https://docs.hunter.sh/en/latest/packages/pkg/Boost.html 8 | hunter_add_package(Boost COMPONENTS random filesystem program_options) 9 | -find_package(Boost CONFIG REQUIRED random filesystem program_options) 10 | +find_package(Boost REQUIRED random filesystem program_options) 11 | 12 | # added from hunter_config 13 | hunter_add_package(Microsoft.GSL) 14 | @@ -16,7 +16,7 @@ find_package(OpenSSL REQUIRED) 15 | 16 | # https://developers.google.com/protocol-buffers/ 17 | hunter_add_package(Protobuf) 18 | -find_package(Protobuf CONFIG REQUIRED) 19 | +find_package(Protobuf REQUIRED) 20 | 21 | # https://docs.hunter.sh/en/latest/packages/pkg/spdlog.html 22 | hunter_add_package(spdlog) 23 | diff --git a/cmake/libp2pConfig.cmake.in b/cmake/libp2pConfig.cmake.in 24 | index 7fd085f..1a7deaf 100644 25 | --- a/cmake/libp2pConfig.cmake.in 26 | +++ b/cmake/libp2pConfig.cmake.in 27 | @@ -4,7 +4,7 @@ include(CMakeFindDependencyMacro) 28 | 29 | find_dependency(Boost CONFIG REQUIRED random filesystem program_options) 30 | find_dependency(OpenSSL REQUIRED) 31 | -find_dependency(Protobuf CONFIG REQUIRED) 32 | +find_dependency(Protobuf REQUIRED) 33 | find_dependency(Threads) 34 | find_dependency(c-ares CONFIG REQUIRED) 35 | find_dependency(fmt CONFIG REQUIRED) 36 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/cpp-libp2p/test-cares.patch: -------------------------------------------------------------------------------- 1 | diff --git a/test/libp2p/injector/CMakeLists.txt b/test/libp2p/injector/CMakeLists.txt 2 | index 9d8c0a3..77b5a56 100644 3 | --- a/test/libp2p/injector/CMakeLists.txt 4 | +++ b/test/libp2p/injector/CMakeLists.txt 5 | @@ -7,6 +7,7 @@ addtest(network_injector_test 6 | target_link_libraries(network_injector_test 7 | Boost::Boost.DI 8 | p2p_default_network 9 | + p2p_cares 10 | ) 11 | 12 | 13 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/default.nix: -------------------------------------------------------------------------------- 1 | { pkgs }: 2 | 3 | # Last updated based on v0.23.257-soramitsu35 4 | 5 | let 6 | # Use nixpkgs as basis 7 | inherit (pkgs) callPackage; 8 | 9 | # Dependencies of dependencies 10 | boost-di = callPackage ./boost-di.nix {}; 11 | 12 | fmt_6 = callPackage ./fmt.nix {}; 13 | 14 | gtest_cmake = callPackage ./googletest.nix {}; 15 | 16 | microsoft-gsl_cmake = callPackage ./microsoft-gsl.nix {}; 17 | 18 | rapidjson_cmake = callPackage ./rapidjson.nix {}; 19 | 20 | soralog = callPackage ./soralog { inherit fmt_6 gtest_cmake; }; 21 | 22 | # Dependencies of libp2p 23 | sqlite-modern-cpp = callPackage ./sqlite-modern-cpp {}; 24 | 25 | tsl-hat-trie = callPackage ./tsl-hat-trie.nix {}; 26 | in { 27 | # Shared dependecies of kagome 28 | inherit boost-di gtest_cmake microsoft-gsl_cmake rapidjson_cmake soralog; 29 | 30 | # Unique dependecies of kagome 31 | backward-cpp_cmake = callPackage ./backward-cpp.nix {}; 32 | 33 | binaryen_cmake = callPackage ./binaryen.nix {}; 34 | 35 | cpp-libp2p = callPackage ./cpp-libp2p { 36 | inherit boost-di gtest_cmake microsoft-gsl_cmake soralog sqlite-modern-cpp tsl-hat-trie; 37 | }; 38 | 39 | erasure-coding-crust = callPackage ./erasure-coding-crust.nix {}; 40 | 41 | jsonrpc-lean = callPackage ./jsonrpc-lean.nix { 42 | inherit rapidjson_cmake; 43 | }; 44 | 45 | libsecp256k1_cmake = callPackage ./libsecp256k1.nix {}; 46 | 47 | prometheus-cpp = callPackage ./prometheus-cpp.nix {}; 48 | 49 | rocksdb_cmake = callPackage ./rocksdb.nix {}; 50 | 51 | scale-codec-cpp = callPackage ./scale-codec-cpp.nix { 52 | inherit microsoft-gsl_cmake; 53 | }; 54 | 55 | schnorrkel-crust = callPackage ./schnorrkel-crust.nix {}; 56 | 57 | wavm = callPackage ./wavm.nix { 58 | # Override for Zen 3 support 59 | inherit (pkgs.llvmPackages_12) libllvm; 60 | }; 61 | 62 | xxHash_cmake = callPackage ./xxhash.nix {}; 63 | } 64 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/erasure-coding-crust.nix: -------------------------------------------------------------------------------- 1 | { rustPlatform, fetchFromGitHub }: 2 | 3 | rustPlatform.buildRustPackage rec { 4 | pname = "erasure-coding-crust"; 5 | version = "0.0.2"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "soramitsu"; 9 | repo = pname; 10 | rev = "v${version}"; 11 | sha256 = "Xao43logjXYUmltGK85doj+qj3YHxdoom/6NVenQYfQ="; 12 | }; 13 | 14 | cargoSha256 = "p7mmQu7iHnEu1u3nw4hKdUMlTCca6d+OTyLaYttnPeg="; 15 | 16 | postInstall = let 17 | cname = "erasure_coding_crust"; 18 | in '' 19 | cp -r include $out 20 | 21 | mkdir -p $out/lib/cmake/${cname} 22 | cat > $out/lib/cmake/${cname}/${cname}Config.cmake << EOF 23 | add_library(${cname}::${cname} STATIC IMPORTED) 24 | set_target_properties(${cname}::${cname} PROPERTIES 25 | INTERFACE_INCLUDE_DIRECTORIES "$out/include" 26 | IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" 27 | IMPORTED_LOCATION_RELEASE "$out/lib/lib${cname}.a" 28 | ) 29 | set_property(TARGET ${cname}::${cname} APPEND PROPERTY 30 | IMPORTED_CONFIGURATIONS RELEASE 31 | ) 32 | target_link_libraries(${cname}::${cname} INTERFACE 33 | pthread 34 | -Wl,--no-as-needed 35 | dl 36 | ) 37 | EOF 38 | ''; 39 | } 40 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/fmt.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, fetchpatch, cmake, enableShared ? true }: 2 | 3 | # NOTE: Hunter uses 6.1.2 4 | stdenv.mkDerivation rec { 5 | pname = "fmt"; 6 | version = "6.2.1"; 7 | 8 | outputs = [ "out" "dev" ]; 9 | 10 | src = fetchFromGitHub { 11 | owner = "fmtlib"; 12 | repo = "fmt"; 13 | rev = version; 14 | sha256 = "1i6nfxazq4d05r3sxyc3ziwkqq7s8rdbv9p16afv66aqmsbqqqic"; 15 | }; 16 | 17 | patches = [ 18 | # Fix BC break breaking Kodi 19 | # https://github.com/xbmc/xbmc/issues/17629 20 | # https://github.com/fmtlib/fmt/issues/1620 21 | (fetchpatch { 22 | url = "https://github.com/fmtlib/fmt/commit/7d01859ef16e6b65bc023ad8bebfedecb088bf81.patch"; 23 | sha256 = "0v8hm5958ih1bmnjr16fsbcmdnq4ykyf6b0hg6dxd5hxd126vnxx"; 24 | }) 25 | 26 | # Fix paths in pkg-config file 27 | # https://github.com/fmtlib/fmt/pull/1657 28 | (fetchpatch { 29 | url = "https://github.com/fmtlib/fmt/commit/78f041ab5b40a1145ba686aeb8013e8788b08cd2.patch"; 30 | sha256 = "1hqp96zl9l3qyvsm7pxl6ah8c26z035q2mz2pqhqa0wvzd1klcc6"; 31 | }) 32 | 33 | # Fix cmake config paths. 34 | (fetchpatch { 35 | url = "https://github.com/fmtlib/fmt/pull/1702.patch"; 36 | sha256 = "18cadqi7nac37ymaz3ykxjqs46rvki396g6qkqwp4k00cmic23y3"; 37 | }) 38 | ]; 39 | 40 | nativeBuildInputs = [ cmake ]; 41 | 42 | cmakeFlags = [ 43 | "-DBUILD_SHARED_LIBS=${if enableShared then "ON" else "OFF"}" 44 | "-DCMAKE_SKIP_BUILD_RPATH=OFF" # for tests 45 | ]; 46 | 47 | doCheck = true; 48 | } 49 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/googletest.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake }: 2 | 3 | stdenv.mkDerivation rec { 4 | name = "googletest-${version}"; 5 | version = "1.11.0"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "google"; 9 | repo = "googletest"; 10 | rev = "release-${version}"; 11 | sha256 = "SjlJxushfry13RGA7BCjYC9oZqV4z6x8dOiHfl/wpF0="; 12 | }; 13 | 14 | nativeBuildInputs = [ cmake ]; 15 | 16 | cmakeFlags = [ 17 | "-DBUILD_SHARED_LIBS=ON" 18 | "-Dgtest_force_shared_crt=TRUE" 19 | "-DCMAKE_CXX_FLAGS=-Wno-deprecated-copy -Wno-unknown-warning-option" 20 | ]; 21 | } 22 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/jsonrpc-lean.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake, rapidjson_cmake }: 2 | 3 | stdenv.mkDerivation { 4 | pname = "jsonrpc-lean"; 5 | version = "2020-04-30"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "xDimon"; 9 | repo = "jsonrpc-lean"; 10 | rev = "6c093da8670d7bf56555f166f8b8151f33a5d741"; 11 | sha256 = "1sxyr8xayldpfycma7hkxp8k9v427mg7a0bb7xkzgs6c4a4mvjqp"; 12 | }; 13 | 14 | nativeBuildInputs = [ cmake ]; 15 | buildInputs = [ rapidjson_cmake ]; 16 | 17 | cmakeFlags = [ "-DHUNTER_ENABLED=false" ]; 18 | } 19 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/libsecp256k1.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "libsecp256k1"; 5 | version = "0.1"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "soramitsu"; 9 | repo = "soramitsu-libsecp256k1"; 10 | rev = "v${version}"; 11 | sha256 = "a2ywjdgNUw1zcXjVE+Uzp19GejRYcuyYqQQFYUVyk1I="; 12 | }; 13 | 14 | nativeBuildInputs = [ cmake ]; 15 | 16 | cmakeFlags = [ 17 | # TODO: Flags just copied from hunter. Fix and run testsuite 18 | "-DSECP256K1_BUILD_TEST=OFF" 19 | ]; 20 | } 21 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/microsoft-gsl.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, catch, cmake }: 2 | 3 | # NOTE: Hunter uses 2.0.0-p0 4 | stdenv.mkDerivation rec { 5 | pname = "microsoft_gsl"; 6 | version = "2.1.0+cmake"; 7 | 8 | src = fetchFromGitHub { 9 | owner = "Microsoft"; 10 | repo = "GSL"; 11 | rev = "0551cad46788790fa421cf1cb0575a1e3e12c131"; 12 | sha256 = "0yzg1q3vdjr8qlaxssazqy5iwllscjh8qd2lqssy0nq0apkxkjzs"; 13 | }; 14 | 15 | nativeBuildInputs = [ catch cmake ]; 16 | 17 | # https://github.com/microsoft/GSL/issues/806 18 | cmakeFlags = [ "-DCMAKE_CXX_FLAGS=-Wno-catch-value" ]; 19 | 20 | doCheck = true; 21 | } 22 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/prometheus-cpp.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "prometheus-cpp"; 5 | version = "0.12.3"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "jupp0r"; 9 | repo = "prometheus-cpp"; 10 | rev = "v${version}"; 11 | sha256 = "0lzfyphk8g8h3f9yv0zpi3jlcb391m1hxv0h0rkrgm3sykmwiaz0"; 12 | fetchSubmodules = true; 13 | }; 14 | 15 | nativeBuildInputs = [ cmake ]; 16 | 17 | cmakeFlags = [ 18 | "-DENABLE_TESTING=OFF" 19 | "-DUSE_THIRDPARTY_LIBRARIES=OFF" 20 | "-DOVERRIDE_CXX_STANDARD_FLAGS=OFF" 21 | "-DENABLE_PULL=OFF" 22 | "-DENABLE_PUSH=OFF" 23 | "-DENABLE_COMPRESSION=OFF" 24 | ]; 25 | } 26 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/rapidjson.nix: -------------------------------------------------------------------------------- 1 | { fetchFromGitHub, rapidjson }: 2 | 3 | rapidjson.overrideAttrs (super: rec { 4 | name = "${super.pname}-${version}"; 5 | version = "1.1.0-66eb606-p0"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "hunter-packages"; 9 | repo = "rapidjson"; 10 | rev = "v${version}"; 11 | sha256 = "19117mlw5z4wwf8ix5hkwjk00hgvngjdiwaj8kqfb069l5m04j32"; 12 | }; 13 | }) 14 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/rocksdb.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "rocksdb"; 5 | version = "7.2.2"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "facebook"; 9 | repo = pname; 10 | rev = "v${version}"; 11 | sha256 = "DoCG/fonq5QjM5RBkhd6mprPFPlvsR4rd7oV7/s8PdE="; 12 | }; 13 | 14 | nativeBuildInputs = [ cmake ]; 15 | 16 | cmakeFlags = [ "-DWITH_TESTS=OFF" "-DPORTABLE=ON" "-DWITH_GFLAGS=OFF" ]; 17 | } 18 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/scale-codec-cpp.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake, boost172, microsoft-gsl_cmake }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "scale-codec-cpp"; 5 | version = "1.0.6"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "soramitsu"; 9 | repo = pname; 10 | rev = "v${version}"; 11 | sha256 = "UotIC2m78Ma5Ep3kLgeUWbPVLNREmX/TncCFfkkDlJ8="; 12 | }; 13 | 14 | nativeBuildInputs = [ cmake ]; 15 | 16 | buildInputs = [ boost172 microsoft-gsl_cmake ]; 17 | 18 | cmakeFlags = [ "-DHUNTER_ENABLED=NO" ]; 19 | } 20 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/schnorrkel-crust.nix: -------------------------------------------------------------------------------- 1 | { rustPlatform, fetchFromGitHub, cmake }: 2 | 3 | rustPlatform.buildRustPackage rec { 4 | pname = "schnorrkel_crust"; 5 | version = "1.0.8"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "Soramitsu"; 9 | repo = "soramitsu-sr25519-crust"; 10 | rev = "62795502ac50b82f3d5a1b084513f6defea002ba"; 11 | sha256 = "qModF/eSqOsuYCjBZk/ikmI8Gov9BKNzjqdPgMwa6dE="; 12 | }; 13 | 14 | cargoSha256 = "4Gx/EoKsQftrwtI9pXj1N/2/pqkwG7s+OImdGKEnmNY="; 15 | 16 | postInstall = '' 17 | cp -r include $out 18 | 19 | mkdir -p $out/lib/cmake/${pname} 20 | cat > $out/lib/cmake/schnorrkel_crust/schnorrkel_crustConfig.cmake << EOF 21 | add_library(schnorrkel_crust::schnorrkel_crust STATIC IMPORTED) 22 | set_target_properties(schnorrkel_crust::schnorrkel_crust PROPERTIES 23 | INTERFACE_INCLUDE_DIRECTORIES "$out/include" 24 | IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" 25 | IMPORTED_LOCATION_RELEASE "$out/lib/libschnorrkel_crust.a" 26 | ) 27 | set_property(TARGET schnorrkel_crust::schnorrkel_crust APPEND PROPERTY 28 | IMPORTED_CONFIGURATIONS RELEASE 29 | ) 30 | target_link_libraries(schnorrkel_crust::schnorrkel_crust INTERFACE 31 | pthread 32 | -Wl,--no-as-needed 33 | dl 34 | ) 35 | EOF 36 | ''; 37 | } 38 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/soralog/default.nix: -------------------------------------------------------------------------------- 1 | { stdenv 2 | , fetchFromGitHub 3 | , cmake 4 | , gtest_cmake 5 | , libyamlcpp 6 | , fmt_6 7 | }: 8 | 9 | stdenv.mkDerivation rec { 10 | pname = "soralog"; 11 | version = "0.1.5"; 12 | 13 | src = fetchFromGitHub { 14 | owner = "soramitsu"; 15 | repo = "soralog"; 16 | rev = "v${version}"; 17 | sha256 = "zjoBQLknPNlNhEIbu60nIYsEZefqmMDfg9myVsAyMq0="; 18 | }; 19 | 20 | patches = [ ./yaml-cpp.patch ]; 21 | 22 | nativeBuildInputs = [ cmake ]; 23 | 24 | buildInputs = [ gtest_cmake ]; 25 | 26 | propagatedBuildInputs = [ libyamlcpp fmt_6 ]; 27 | 28 | cmakeFlags = [ "-DHUNTER_ENABLED=OFF" "-DTESTING=OFF" "-DEXAMPLES=OFF" ]; 29 | } 30 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/soralog/yaml-cpp.patch: -------------------------------------------------------------------------------- 1 | +++ a/src/CMakeLists.txt 2 | --- b/src/CMakeLists.txt 3 | @@ -70,7 +70,7 @@ add_library(configurator_yaml 4 | impl/configurator_from_yaml.cpp 5 | ) 6 | target_link_libraries(configurator_yaml 7 | - yaml-cpp::yaml-cpp 8 | + yaml-cpp 9 | configurator 10 | ) 11 | 12 | 13 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/sqlite-modern-cpp/default.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake, sqlite }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "sqlite-modern-cpp"; 5 | version = "3.2+cmake"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "soramitsu"; 9 | repo = "libp2p-sqlite-modern-cpp"; 10 | rev = "fc3b700064cb57ab6b598c9bc7a12b2842f78da2"; 11 | sha256 = "0r5b3w0lawbyd5pa31jhj0jyz52viqabijdyykw5p9n4gninrw21"; 12 | }; 13 | 14 | patches = [ ./package_name.patch ]; 15 | 16 | nativeBuildInputs = [ cmake ]; 17 | propagatedBuildInputs = [ sqlite ]; 18 | 19 | cmakeFlags = [ "-DHUNTER_ENABLED=OFF" ]; 20 | 21 | doCheck = true; 22 | } 23 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/sqlite-modern-cpp/package_name.patch: -------------------------------------------------------------------------------- 1 | diff --git a/CMakeLists.txt b/CMakeLists.txt 2 | index f130229..fd32200 100644 3 | --- a/CMakeLists.txt 4 | +++ b/CMakeLists.txt 5 | @@ -18,7 +18,7 @@ project("SQLiteModernCpp" 6 | ) 7 | 8 | hunter_add_package(sqlite3) 9 | -find_package(sqlite3 CONFIG REQUIRED) 10 | +find_package(SQLite3 REQUIRED) 11 | 12 | add_library(${PROJECT_NAME} INTERFACE) 13 | target_include_directories( 14 | @@ -26,7 +26,7 @@ target_include_directories( 15 | $ 16 | $ 17 | ) 18 | -target_link_libraries(${PROJECT_NAME} INTERFACE sqlite3::sqlite3) 19 | +target_link_libraries(${PROJECT_NAME} INTERFACE SQLite::SQLite3) 20 | target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) 21 | 22 | include(GNUInstallDirs) 23 | diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in 24 | index 3858941..669f010 100644 25 | --- a/cmake/Config.cmake.in 26 | +++ b/cmake/Config.cmake.in 27 | @@ -1,6 +1,6 @@ 28 | @PACKAGE_INIT@ 29 | 30 | -find_package(sqlite3 CONFIG REQUIRED) 31 | +find_package(SQLite3 REQUIRED) 32 | 33 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 34 | check_required_components("@PROJECT_NAME@") 35 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/tsl-hat-trie.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "tsl_hat_trie"; 5 | version = "1.0.0"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "masterjedy"; 9 | repo = "hat-trie"; 10 | rev = "4fdfc75e75276185eed4b748ea09671601101b8e"; 11 | sha256 = "4oeTE5cREJdyUdFDc+q/KmOc6CyB+sBL99dZFpRtAlY="; 12 | }; 13 | 14 | nativeBuildInputs = [ cmake ]; 15 | } 16 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/wavm.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake, libllvm }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "WAVM"; 5 | version = "1.0.6"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "soramitsu"; 9 | repo = "WAVM"; 10 | rev = version; 11 | sha256 = "RL8iam69DO2TkcSAqJG2CW/pgidFPFKJ2jHyY1HjHnc="; 12 | }; 13 | 14 | nativeBuildInputs = [ cmake ]; 15 | 16 | propagatedBuildInputs = [ libllvm ]; 17 | 18 | cmakeFlags = [ "-DHUNTER_ENABLED=NO" ]; 19 | } 20 | -------------------------------------------------------------------------------- /.nix/kagome/dependencies/xxhash.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, cmake }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "xxHash"; 5 | version = "0.6.5-p0"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "hunter-packages"; 9 | repo = "xxHash"; 10 | rev = version; 11 | sha256 = "1ccppwg65wcydl2293yr1q81fz7d1bzr8iv8wq3yl28x0q9b8jbs"; 12 | }; 13 | 14 | nativeBuildInputs = [ cmake ]; 15 | } 16 | -------------------------------------------------------------------------------- /.nix/kagome/zstd.patch: -------------------------------------------------------------------------------- 1 | diff --git a/core/runtime/common/CMakeLists.txt b/core/runtime/common/CMakeLists.txt 2 | index 4220f3b7..659a4687 100644 3 | --- a/core/runtime/common/CMakeLists.txt 4 | +++ b/core/runtime/common/CMakeLists.txt 5 | @@ -25,7 +25,7 @@ add_library(uncompress_if_needed 6 | uncompress_code_if_needed.cpp 7 | ) 8 | target_link_libraries(uncompress_if_needed 9 | - zstd::libzstd_static 10 | + zstd 11 | ) 12 | kagome_install(uncompress_if_needed) 13 | 14 | -------------------------------------------------------------------------------- /.nix/packages.nix: -------------------------------------------------------------------------------- 1 | { self, naersk, pkgs, submodules }: 2 | 3 | let 4 | # Shared source inputs 5 | sources = { 6 | # Add polkadot-tests source 7 | polkadot-tests = { 8 | src = self; 9 | version = if self ? rev 10 | then (builtins.substring 0 7 self.rev) 11 | else self.lastModifiedDate; 12 | }; 13 | 14 | # NOTE: Flake should provide submodules seperately 15 | #gossamer-submodule = builtins.fetchTree self.modules."hosts/gossamer"; 16 | #kagome-submodule = builtins.fetchTree self.modules."hosts/kagome"; 17 | #substrate-submodule = builtins.fetchTree self.modules."hosts/substrate"; 18 | } // submodules; 19 | 20 | # Implementation dependency derivations (buildable) 21 | dependencies = import ./kagome/dependencies { inherit pkgs; }; 22 | 23 | # Implementation derivations (buildable) 24 | hosts = with pkgs; { 25 | # Go implementations 26 | gossamer-host = callPackage ./gossamer { 27 | inherit (sources) gossamer-submodule; 28 | }; 29 | 30 | # C++ implementations 31 | kagome-host = callPackage ./kagome (dependencies // { 32 | inherit (sources) kagome-submodule; 33 | }); 34 | 35 | # Rust implementations 36 | substrate-host = callPackage ./substrate { 37 | inherit (sources) substrate-submodule; 38 | inherit naersk; 39 | }; 40 | }; 41 | 42 | # Specification Testsuite binaries (buildable) 43 | testsuite = with pkgs; { 44 | # Adapters 45 | substrate-adapter = callPackage ../adapters/substrate { 46 | inherit (sources) polkadot-tests; 47 | inherit naersk; 48 | }; 49 | kagome-adapter = callPackage ../adapters/kagome { 50 | inherit (sources) polkadot-tests; 51 | inherit (hosts) kagome-host; 52 | inherit (dependencies) scale-codec-cpp; 53 | }; 54 | gossamer-adapter = callPackage ../adapters/gossamer { 55 | inherit (sources) polkadot-tests; 56 | inherit (sources) gossamer-submodule; 57 | }; 58 | 59 | # Runtimes 60 | hostapi-runtime = callPackage ../runtimes/hostapi { 61 | inherit (sources) polkadot-tests; 62 | inherit naersk; 63 | }; 64 | tester-runtime = callPackage ../runtimes/tester { 65 | inherit (sources) polkadot-tests; 66 | inherit naersk; 67 | }; 68 | 69 | # Testsuite incl. fixtures 70 | polkadot-testsuite = callPackage ./testsuite.nix { 71 | inherit (sources) polkadot-tests; 72 | }; 73 | }; 74 | 75 | # Export some of the package sets as subset. 76 | virtual = { 77 | inherit hosts dependencies testsuite; 78 | }; 79 | in 80 | sources // dependencies // hosts // testsuite // virtual 81 | -------------------------------------------------------------------------------- /.nix/substrate/default.nix: -------------------------------------------------------------------------------- 1 | { substrate-submodule 2 | , lib 3 | , naersk 4 | , clang 5 | , llvmPackages 6 | , protobuf 7 | }: 8 | 9 | naersk.buildPackage rec { 10 | name = "substrate-host"; 11 | 12 | src = substrate-submodule; 13 | version = substrate-submodule.shortRev; 14 | 15 | nativeBuildInputs = [ clang ]; 16 | 17 | LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; 18 | PROTOC = "${protobuf}/bin/protoc"; 19 | 20 | # Currently not needed 21 | SKIP_WASM_BUILD = 1; 22 | 23 | # Needs WASM runtimes. 24 | doCheck = false; 25 | 26 | postInstall = '' 27 | mv $out/bin/polkadot $out/bin/${name} 28 | ''; 29 | } 30 | -------------------------------------------------------------------------------- /.nix/substrate/env.nix: -------------------------------------------------------------------------------- 1 | { lib, mkShell, rustToolchain, cmake, openssl, pkgconfig, protobuf, llvmPackages, rocksdb }: 2 | 3 | let 4 | version = lib.getVersion rustToolchain; 5 | in 6 | mkShell { 7 | name = "substrate-env-${version}"; 8 | 9 | nativeBuildInputs = [ 10 | rustToolchain 11 | cmake # for wabt-sys 12 | ]; 13 | 14 | buildInputs = [ 15 | openssl #? 16 | pkgconfig #? 17 | protobuf 18 | llvmPackages.clang-unwrapped 19 | llvmPackages.libclang 20 | ]; 21 | 22 | PROTOC = "${protobuf}/bin/protoc"; 23 | PROTOC_INCLUDE = "${protobuf}/include"; 24 | LIBCLANG_PATH = "${llvmPackages.libclang}/lib"; 25 | ROCKSDB_LIB_DIR = "${rocksdb}/lib"; 26 | } 27 | -------------------------------------------------------------------------------- /.nix/testsuite.nix: -------------------------------------------------------------------------------- 1 | { polkadot-tests, stdenv }: 2 | 3 | stdenv.mkDerivation { 4 | pname = "polkadot-testsuite"; 5 | inherit (polkadot-tests) src version; 6 | 7 | phases = [ "unpackPhase" "installPhase" ]; 8 | 9 | installPhase = '' 10 | mkdir -p $out/bin 11 | cp -r runtests.jl fixtures helpers $out/bin 12 | ''; 13 | 14 | passthru.exePath = "/bin/runtests.jl"; 15 | } 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | HOSTS = substrate kagome gossamer 2 | RUNTIMES = hostapi tester 3 | 4 | ALIASES_ADAPTER := $(patsubst %,%-adapter,$(HOSTS)) 5 | ALIASES_RUNTIME := $(patsubst %,%-runtime,$(RUNTIMES)) 6 | ALIASES_HOST := $(patsubst %,%-host,$(HOSTS)) 7 | 8 | 9 | .PHONY: all init adapters $(ALIASES_ADAPTER) runtimes $(ALIASES_RUNTIME) hosts $(ALIASES_HOST) test clean 10 | 11 | 12 | all: adapters runtimes hosts 13 | 14 | 15 | bin lib: 16 | mkdir -p $@/ 17 | 18 | init: bin lib 19 | 20 | 21 | adapters: $(ALIASES_ADAPTER) 22 | 23 | $(ALIASES_ADAPTER): %-adapter: init 24 | $(MAKE) -C adapters/$* 25 | 26 | 27 | runtimes: $(ALIASES_RUNTIME) 28 | 29 | $(ALIASES_RUNTIME): %-runtime: init 30 | $(MAKE) -C runtimes/$* 31 | 32 | hostapi-runtime-expmem: init 33 | $(MAKE) -C runtimes/hostapi install-expmem 34 | 35 | 36 | hosts: $(ALIASES_HOST) 37 | 38 | $(ALIASES_HOST): %-host: init 39 | $(MAKE) -C hosts $* 40 | 41 | 42 | test: all 43 | ./runtests.jl 44 | 45 | 46 | version: 47 | @for a in $(HOSTS); do echo -n "$$a-adapter: "; $(MAKE) -sC adapters/$$a $@; done 48 | @for r in $(RUNTIMES); do echo -n "$$r-runtime: "; $(MAKE) -sC runtimes/$$r $@; done 49 | @make -sC hosts $@ 50 | 51 | 52 | clean: 53 | for a in $(HOSTS); do $(MAKE) -C adapters/$$a $@; done 54 | for t in $(RUNTIMES); do $(MAKE) -C runtimes/$$t $@; done 55 | $(MAKE) -C hosts $@ 56 | rm -rf bin/ lib/ 57 | -------------------------------------------------------------------------------- /adapters/gossamer/.gitignore: -------------------------------------------------------------------------------- 1 | gossamer-adapter 2 | -------------------------------------------------------------------------------- /adapters/gossamer/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all build install version clean 2 | 3 | all: install 4 | 5 | build: 6 | go build -v 7 | 8 | install: build 9 | cp gossamer-adapter ../../bin/ 10 | cp ~/go/pkg/mod/github.com/wasmerio/go-ext-wasm@*/wasmer/libwasmer.so ../../lib/ 11 | chmod u+w ../../lib/libwasmer.so 12 | 13 | version: 14 | @grep "github.com/ChainSafe/gossamer" go.mod | cut -d' ' -f2 15 | 16 | clean: 17 | rm -f gossamer-adapter 18 | -------------------------------------------------------------------------------- /adapters/gossamer/default.nix: -------------------------------------------------------------------------------- 1 | { polkadot-tests, gossamer-submodule, buildGo118Module, patchelf, glibc }: 2 | 3 | let 4 | modRoot = "adapters/gossamer"; 5 | 6 | postPatch = '' 7 | substituteInPlace "${modRoot}/go.mod" --replace "../../hosts/gossamer" "${gossamer-submodule}" 8 | ''; 9 | in buildGo118Module rec { 10 | pname = "gossamer-adapter"; 11 | inherit (polkadot-tests) src version; 12 | 13 | inherit modRoot postPatch; 14 | overrideModAttrs = _: { inherit postPatch; }; 15 | 16 | proxyVendor = true; 17 | 18 | vendorSha256 = "yxdS8+tAsUveWS11aerqal/wrrFdvZf4/Y7GrzHJhCg="; 19 | 20 | nativeBuildInputs = [ patchelf ]; 21 | 22 | postInstall = '' 23 | mkdir $out/lib 24 | cp /build/go/pkg/mod/github.com/wasmerio/go-ext-wasm@*/wasmer/libwasmer.so $out/lib 25 | patchelf --set-rpath "$out/lib:${glibc}/lib" $out/bin/${pname} 26 | ''; 27 | } 28 | -------------------------------------------------------------------------------- /adapters/gossamer/go.mod: -------------------------------------------------------------------------------- 1 | module w3f/gossamer-adapter 2 | 3 | require ( 4 | github.com/ChainSafe/gossamer v0.0.0-submodule 5 | gopkg.in/yaml.v3 v3.0.1 6 | ) 7 | 8 | require ( 9 | github.com/ChainSafe/chaindb v0.1.5-0.20220708005902-df45dbc8e840 // indirect 10 | github.com/ChainSafe/go-schnorrkel v1.0.1-0.20220711122024-027d287d27bf // indirect 11 | github.com/ChainSafe/log15 v1.0.0 // indirect 12 | github.com/OneOfOne/xxhash v1.2.8 // indirect 13 | github.com/beorn7/perks v1.0.1 // indirect 14 | github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect 15 | github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect 16 | github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.12 // indirect 17 | github.com/cespare/xxhash v1.1.0 // indirect 18 | github.com/cespare/xxhash/v2 v2.1.2 // indirect 19 | github.com/cosmos/go-bip39 v1.0.0 // indirect 20 | github.com/davecgh/go-spew v1.1.1 // indirect 21 | github.com/decred/base58 v1.0.3 // indirect 22 | github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect 23 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect 24 | github.com/dgraph-io/badger/v2 v2.2007.4 // indirect 25 | github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de // indirect 26 | github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 // indirect 27 | github.com/dustin/go-humanize v1.0.0 // indirect 28 | github.com/ethereum/go-ethereum v1.10.26 // indirect 29 | github.com/fatih/color v1.14.0 // indirect 30 | github.com/go-stack/stack v1.8.1 // indirect 31 | github.com/golang/mock v1.6.0 // indirect 32 | github.com/golang/protobuf v1.5.2 // indirect 33 | github.com/golang/snappy v0.0.4 // indirect 34 | github.com/gtank/merlin v0.1.1 // indirect 35 | github.com/gtank/ristretto255 v0.1.2 // indirect 36 | github.com/ipfs/go-cid v0.2.0 // indirect 37 | github.com/klauspost/compress v1.15.15 // indirect 38 | github.com/klauspost/cpuid/v2 v2.1.0 // indirect 39 | github.com/kr/pretty v0.2.1 // indirect 40 | github.com/kr/text v0.2.0 // indirect 41 | github.com/mattn/go-colorable v0.1.13 // indirect 42 | github.com/mattn/go-isatty v0.0.17 // indirect 43 | github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect 44 | github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect 45 | github.com/minio/sha256-simd v1.0.0 // indirect 46 | github.com/mr-tron/base58 v1.2.0 // indirect 47 | github.com/multiformats/go-base32 v0.0.4 // indirect 48 | github.com/multiformats/go-base36 v0.1.0 // indirect 49 | github.com/multiformats/go-multiaddr v0.8.0 // indirect 50 | github.com/multiformats/go-multibase v0.1.1 // indirect 51 | github.com/multiformats/go-multihash v0.2.1 // indirect 52 | github.com/multiformats/go-varint v0.0.6 // indirect 53 | github.com/pierrec/xxHash v0.1.5 // indirect 54 | github.com/pkg/errors v0.9.1 // indirect 55 | github.com/pmezard/go-difflib v1.0.0 // indirect 56 | github.com/prometheus/client_golang v1.14.0 // indirect 57 | github.com/prometheus/client_model v0.3.0 // indirect 58 | github.com/prometheus/common v0.37.0 // indirect 59 | github.com/prometheus/procfs v0.8.0 // indirect 60 | github.com/qdm12/gotree v0.2.0 // indirect 61 | github.com/spaolacci/murmur3 v1.1.0 // indirect 62 | github.com/stretchr/testify v1.8.1 // indirect 63 | github.com/vedhavyas/go-subkey v1.0.3 // indirect 64 | github.com/wasmerio/go-ext-wasm v0.3.2-0.20200326095750-0a32be6068ec // indirect 65 | golang.org/x/crypto v0.1.0 // indirect 66 | golang.org/x/exp v0.0.0-20230127140709-cafedaf64729 // indirect 67 | golang.org/x/net v0.1.0 // indirect 68 | golang.org/x/sys v0.3.0 // indirect 69 | golang.org/x/text v0.6.0 // indirect 70 | google.golang.org/protobuf v1.28.1 // indirect 71 | lukechampine.com/blake3 v1.1.7 // indirect 72 | ) 73 | 74 | replace github.com/ChainSafe/gossamer v0.0.0-submodule => ../../hosts/gossamer 75 | 76 | go 1.18 77 | -------------------------------------------------------------------------------- /adapters/gossamer/host_api/allocator.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | package host_api 19 | 20 | import ( 21 | "fmt" 22 | "bytes" 23 | 24 | "github.com/ChainSafe/gossamer/lib/runtime" 25 | "github.com/ChainSafe/gossamer/pkg/scale" 26 | ) 27 | 28 | // Test for ext_allocator_malloc_version_1 and ext_allocator_free_version_1 29 | func test_allocator_malloc_free(r runtime.Instance, value string) error { 30 | 31 | // Encode inputs 32 | value_enc, err := scale.Marshal([]byte(value)) 33 | if err != nil { 34 | return fmt.Errorf("Encoding value failed: %w", err) 35 | } 36 | 37 | // The Wasm function tests both the allocation and freeing of the buffer 38 | result_enc, err := r.Exec("rtm_ext_allocator_malloc_version_1", value_enc) 39 | if err != nil { 40 | return fmt.Errorf("Execution failed: %w", err) 41 | } 42 | 43 | // Decode and print output 44 | var result []byte 45 | err = scale.Unmarshal(result_enc, &result) 46 | if err != nil { 47 | return fmt.Errorf("Decoding result failed: %w", err) 48 | } 49 | 50 | if !bytes.Equal(result, []byte(value)) { 51 | return fmt.Errorf("Value is different: %s", result) 52 | } 53 | 54 | fmt.Printf("%s\n", result) 55 | 56 | return nil 57 | } 58 | -------------------------------------------------------------------------------- /adapters/gossamer/host_api/child_storage.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | package host_api 19 | 20 | import ( 21 | "errors" 22 | "fmt" 23 | "bytes" 24 | 25 | "github.com/ChainSafe/gossamer/lib/runtime" 26 | "github.com/ChainSafe/gossamer/pkg/scale" 27 | ) 28 | 29 | // -- Helpers -- 30 | 31 | // Helper function to call rtm_ext_default_child_storage_set_version_1 32 | func child_storage_set(r runtime.Instance, child, key, value []byte) error { 33 | // Encode inputs 34 | child_enc, err := scale.Marshal(child) 35 | if err != nil { 36 | return fmt.Errorf("Encoding child failed: %w", err) 37 | } 38 | 39 | key_enc, err := scale.Marshal(key) 40 | if err != nil { 41 | return fmt.Errorf("Encoding key failed: %w", err) 42 | } 43 | 44 | value_enc, err := scale.Marshal(value) 45 | if err != nil { 46 | return fmt.Errorf("Encoding value failed: %w", err) 47 | } 48 | 49 | args_enc := append(append(child_enc, key_enc...), value_enc...) 50 | 51 | // Set key to value 52 | _, err = r.Exec("rtm_ext_default_child_storage_set_version_1", args_enc) 53 | if err != nil { 54 | return fmt.Errorf("Execution failed: %w", err) 55 | } 56 | 57 | return nil 58 | } 59 | 60 | // Helper function to call rtm_ext_default_child_storage_get_version_1 61 | func child_storage_get(r runtime.Instance, child, key []byte) (*[]byte, error) { 62 | // Encode inputs 63 | child_enc, err := scale.Marshal(child) 64 | if err != nil { 65 | return nil, fmt.Errorf("Encoding child failed: %w", err) 66 | } 67 | 68 | key_enc, err := scale.Marshal(key) 69 | if err != nil { 70 | return nil, fmt.Errorf("Encoding key failed: %w", err) 71 | } 72 | 73 | // Retrieve key 74 | value_enc, err := r.Exec("rtm_ext_default_child_storage_get_version_1", append(child_enc, key_enc...)) 75 | if err != nil { 76 | return nil, fmt.Errorf("Execution failed: %w", err) 77 | } 78 | 79 | var value_opt *[]byte 80 | err = scale.Unmarshal(value_enc, &value_opt) 81 | if err != nil { 82 | return nil, fmt.Errorf("Decoding value failed: %w", err) 83 | } 84 | return value_opt, nil 85 | } 86 | 87 | // -- Tests -- 88 | 89 | // Test for rtm_ext_child_storage_set_version_1 and rtm_ext_child_storage_get_version_1 90 | func test_child_storage_set_get(r runtime.Instance, child1, child2, key, value string) error { 91 | // Get invalid key 92 | none1, err := child_storage_get(r, []byte(child1), []byte(key)) 93 | if err != nil { 94 | return err 95 | } 96 | 97 | if none1 != nil { 98 | return errors.New("Child1/Key is not empty") 99 | } 100 | 101 | // Set key to value 102 | err = child_storage_set(r, []byte(child1), []byte(key), []byte(value)) 103 | if err != nil { 104 | return err 105 | } 106 | 107 | // Get invalid key (wrong child key) 108 | none2, err := child_storage_get(r, []byte(child2), []byte(key)) 109 | if err != nil { 110 | return err 111 | } 112 | 113 | if none2 != nil { 114 | return errors.New("Child2/Key is not empty") 115 | } 116 | 117 | // Get valid key 118 | some, err := child_storage_get(r, []byte(child1), []byte(key)) 119 | if err != nil { 120 | return err 121 | } 122 | 123 | if some == nil { 124 | return errors.New("Child1/Key is not set") 125 | } 126 | 127 | if !bytes.Equal(*some, []byte(value)) { 128 | return fmt.Errorf("Value is different: %s", *some) 129 | } 130 | 131 | fmt.Printf("%s\n", *some) 132 | 133 | return nil 134 | } 135 | -------------------------------------------------------------------------------- /adapters/gossamer/host_api/crypto.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | package host_api 19 | 20 | import ( 21 | "bytes" 22 | "errors" 23 | "fmt" 24 | 25 | "github.com/ChainSafe/gossamer/lib/runtime" 26 | "github.com/ChainSafe/gossamer/pkg/scale" 27 | ) 28 | 29 | // -- Helpers -- 30 | 31 | // DUMY in ASCII and reversed to achieve same encoding as 4-byte static array 32 | const DUMY_KEY_ID int32 = 0x796d7564 33 | 34 | // Helper function to call rtm_ext_crypto__generate_version_1 35 | func crypto_generate(r runtime.Instance, suite, seed string) ([]byte, error) { 36 | // Encode inputs 37 | id_enc, err := scale.Marshal(DUMY_KEY_ID) 38 | if err != nil { 39 | return nil, fmt.Errorf("Encoding key id failed: %w", err) 40 | } 41 | 42 | seed_bin := []byte(seed) 43 | seed_enc, err := scale.Marshal(&seed_bin) // optional 44 | if err != nil { 45 | return nil, fmt.Errorf("Encoding seed failed: %w", err) 46 | } 47 | 48 | // Generate new public key 49 | pk, err := r.Exec("rtm_ext_crypto_" + suite + "_generate_version_1", append(id_enc, seed_enc...)) 50 | if err != nil { 51 | return nil, fmt.Errorf("Execution failed: %w", err) 52 | } 53 | 54 | return pk, nil 55 | } 56 | 57 | // Helper function to call rtm_ext_crypto__public_keys_version_1 58 | func crypto_public_keys(r runtime.Instance, suite string) ([]byte, error) { 59 | // Encode input 60 | id_enc, err := scale.Marshal(DUMY_KEY_ID) 61 | if err != nil { 62 | return nil, fmt.Errorf("Encoding key id failed: %w", err) 63 | } 64 | 65 | // Request all know public keys 66 | keys, err := r.Exec("rtm_ext_crypto_" + suite + "_public_keys_version_1", id_enc) 67 | if err != nil { 68 | return nil, fmt.Errorf("Execution failed: %w", err) 69 | } 70 | 71 | return keys, nil 72 | } 73 | 74 | // Helper function to call rtm_ext_crypto__sign_version_1 75 | func crypto_sign(r runtime.Instance, suite string, pubkey []byte, msg string) (*[]byte, error) { 76 | // Encode inputs 77 | id_enc, err := scale.Marshal(DUMY_KEY_ID) 78 | if err != nil { 79 | return nil, fmt.Errorf("Encoding key id failed: %w", err) 80 | } 81 | 82 | msg_enc, err := scale.Marshal([]byte(msg)) 83 | if err != nil { 84 | return nil, fmt.Errorf("Encoding message failed: %w", err) 85 | } 86 | 87 | args_enc := append(append(id_enc, pubkey...), msg_enc...) 88 | 89 | // Sign message 90 | sig_enc, err := r.Exec("rtm_ext_crypto_" + suite + "_sign_version_1", args_enc) 91 | if err != nil { 92 | return nil, fmt.Errorf("Execution failed: %w", err) 93 | } 94 | 95 | // Decode and return result 96 | if sig_enc[0] != 0 { 97 | sig_dec := sig_enc[1:] 98 | return &sig_dec, nil 99 | } 100 | 101 | return nil, nil 102 | } 103 | 104 | // Helper function to call rtm_ext_crypto__verify_version_1 105 | func crypto_verify(r runtime.Instance, suite string, sig []byte, msg string, pubkey []byte) (bool, error) { 106 | // Encode inputs 107 | msg_enc, err := scale.Marshal([]byte(msg)) 108 | if err != nil { 109 | return false, fmt.Errorf("Encoding message failed: %w", err) 110 | } 111 | 112 | args_enc := append(append(sig, msg_enc...), pubkey...) 113 | 114 | // Verify signature 115 | res_enc, err := r.Exec("rtm_ext_crypto_" + suite + "_verify_version_1", args_enc) 116 | if err != nil { 117 | return false, fmt.Errorf("Execution failed: %w", err) 118 | } 119 | 120 | // Decode and return result 121 | var res bool 122 | err = scale.Unmarshal(res_enc, &res) 123 | if err != nil { 124 | return false, fmt.Errorf("Decoding result failed: %w", err) 125 | } 126 | return res, nil 127 | } 128 | 129 | // -- Tests -- 130 | 131 | // Test for ext_crypto__generate_version_1 132 | func test_crypto_generate(r runtime.Instance, suite, seed string) error { 133 | // Generate new key and print result 134 | pk, err := crypto_generate(r, suite, seed) 135 | if err != nil { 136 | return err 137 | } 138 | 139 | if len(pk) != 32 { 140 | return fmt.Errorf("Public key has incorrect size: %d", len(pk)) 141 | } 142 | 143 | fmt.Printf("%x\n", pk) 144 | 145 | return nil 146 | } 147 | 148 | // Test for ext_crypto__public_keys_version_1 149 | func test_crypto_public_keys(r runtime.Instance, suite, seed1, seed2 string) error { 150 | // Generate two new keys 151 | pk1, err := crypto_generate(r, suite, seed1) 152 | if err != nil { 153 | return err 154 | } 155 | 156 | pk2, err := crypto_generate(r, suite, seed2) 157 | if err != nil { 158 | return err 159 | } 160 | 161 | // Retrieve all public keys 162 | keys, err := crypto_public_keys(r, suite) 163 | if err != nil { 164 | return err 165 | } 166 | 167 | // Check result 168 | if len(keys) != 65 || keys[0] != 8 { 169 | return fmt.Errorf("Pubkeys size missmatch: %d %d", len(keys), keys[0]) 170 | } 171 | 172 | key1 := keys[1:33] 173 | key2 := keys[33:65] 174 | 175 | if !bytes.Equal(pk1, key1) && !bytes.Equal(pk1, key2) { 176 | return errors.New("Keystore does not include pubkey 1") 177 | } 178 | 179 | if !bytes.Equal(pk2, key1) && !bytes.Equal(pk2, key2) { 180 | return errors.New("Keystore does not include pubkey 2") 181 | } 182 | 183 | fmt.Printf("1. Public key: %x\n", key1) 184 | fmt.Printf("2. Public key: %x\n", key2) 185 | 186 | return nil 187 | } 188 | 189 | // Test for ext_crypto__sign_version_1 190 | func test_crypto_sign(r runtime.Instance, suite, seed, msg string) error { 191 | // Generate a key 192 | pk, err := crypto_generate(r, suite, seed) 193 | if err != nil { 194 | return err 195 | } 196 | 197 | // Sign message 198 | sig, err := crypto_sign(r, suite, pk, msg) 199 | if err != nil { 200 | return err 201 | } 202 | 203 | // Check and print result 204 | if sig == nil { 205 | return errors.New("No signature received") 206 | } 207 | 208 | if len(*sig) != 64 { 209 | return fmt.Errorf("Signature has incorrect size: %d", len(*sig)) 210 | } 211 | 212 | fmt.Println("Message: ", msg) 213 | fmt.Printf("Public key: %x\n", pk) 214 | fmt.Printf("Signature: %x\n", *sig) 215 | 216 | return nil 217 | } 218 | 219 | // Test for ext_crypto__verify_version_1 220 | func test_crypto_verify(r runtime.Instance, suite, seed, msg string) error { 221 | // Generate a key 222 | pk, err := crypto_generate(r, suite, seed) 223 | if err != nil { 224 | return err 225 | } 226 | 227 | // Sign message 228 | sig, err := crypto_sign(r, suite, pk, msg) 229 | if err != nil { 230 | return err 231 | } 232 | 233 | if sig == nil { 234 | return errors.New("No signature received") 235 | } 236 | 237 | // Verify signature 238 | valid, err := crypto_verify(r, suite, *sig, msg, pk) 239 | 240 | if !valid { 241 | return errors.New("Verifying signature failed") 242 | } 243 | 244 | // Print result 245 | fmt.Println("Message: ", msg) 246 | fmt.Printf("Public key: %x\n", pk) 247 | fmt.Printf("Signature: %x\n", *sig) 248 | 249 | if valid { 250 | fmt.Println("GOOD SIGNATURE"); 251 | } else { 252 | fmt.Println("BAD SIGNATURE"); 253 | } 254 | 255 | return nil 256 | } 257 | -------------------------------------------------------------------------------- /adapters/gossamer/host_api/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | package host_api 19 | 20 | // Empty error to indicate missing implementation 21 | type MissingImplementation struct {} 22 | 23 | func (e MissingImplementation) Error() string { return "Not implemented" } 24 | -------------------------------------------------------------------------------- /adapters/gossamer/host_api/hashing.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | // this file provide a command line interface to call scale codec go library 19 | 20 | package host_api 21 | 22 | import ( 23 | "fmt" 24 | 25 | "github.com/ChainSafe/gossamer/lib/runtime" 26 | "github.com/ChainSafe/gossamer/pkg/scale" 27 | ) 28 | 29 | // Simple wrapper to test hash function that input and output byte arrays 30 | func test_hashing(r runtime.Instance, name, input string) error { 31 | 32 | enc, err := scale.Marshal([]byte(input)) 33 | if err != nil { 34 | return fmt.Errorf("Encoding failed: %w", err) 35 | } 36 | 37 | output, err := r.Exec("rtm_" + name, enc) 38 | if err != nil { 39 | return fmt.Errorf("Execution failed: %w", err) 40 | } 41 | 42 | var dec []byte 43 | err = scale.Unmarshal(output, &dec) 44 | if err != nil { 45 | return fmt.Errorf("Decoding failed: %w", err) 46 | } 47 | 48 | fmt.Printf("%x\n", dec[:]) 49 | 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /adapters/gossamer/host_api/trie.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | package host_api 19 | 20 | import ( 21 | "fmt" 22 | 23 | "github.com/ChainSafe/gossamer/lib/runtime" 24 | "github.com/ChainSafe/gossamer/pkg/scale" 25 | ) 26 | 27 | 28 | func test_trie_root(r runtime.Instance, key1, value1, key2, value2, key3, value3 string) error { 29 | // Construct and encode input 30 | trie := []string{key1, value1, key2, value2, key3, value3} 31 | 32 | trie_enc, err := scale.Marshal(trie) 33 | if err != nil { 34 | return fmt.Errorf("Encoding input failed: %w", err) 35 | } 36 | 37 | // Change encoding to key-value tuples by fixing encoded list length 38 | trie_enc[0] = trie_enc[0] / 2 39 | 40 | // Compute ordered root hash 41 | hash_enc, err := r.Exec("rtm_ext_trie_blake2_256_root_version_1", trie_enc) 42 | 43 | if err != nil { 44 | return fmt.Errorf("Execution failed: %w", err) 45 | } 46 | 47 | // Decode and print result 48 | var hash []byte 49 | err = scale.Unmarshal(hash_enc, &hash) 50 | if err != nil { 51 | return fmt.Errorf("Decoding value failed: %w", err) 52 | } 53 | 54 | fmt.Printf("%x\n", hash[:]) 55 | 56 | return nil 57 | } 58 | 59 | func test_trie_ordered_root(r runtime.Instance, value1, value2, value3 string) error { 60 | // Construct and encode input 61 | trie := []string{value1, value2, value3} 62 | 63 | trie_enc, err := scale.Marshal(trie) 64 | if err != nil { 65 | return fmt.Errorf("Encoding input failed: %w", err) 66 | } 67 | 68 | // Compute ordered root hash 69 | hash_enc, err := r.Exec("rtm_ext_trie_blake2_256_ordered_root_version_1", trie_enc) 70 | 71 | if err != nil { 72 | return fmt.Errorf("Execution failed: %w", err) 73 | } 74 | 75 | // Decode and print result 76 | var hash []byte 77 | err = scale.Unmarshal(hash_enc, &hash) 78 | if err != nil { 79 | return fmt.Errorf("Decoding value failed: %w", err) 80 | } 81 | 82 | fmt.Printf("%x\n", hash[:]) 83 | 84 | return nil 85 | } 86 | -------------------------------------------------------------------------------- /adapters/gossamer/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | // this file provide a command line interface to call scale codec go library 19 | 20 | package main 21 | 22 | import ( 23 | "fmt" 24 | "os" 25 | 26 | "w3f/gossamer-adapter/host_api" 27 | ) 28 | 29 | func usage() { 30 | fmt.Println("usage: ", os.Args[0], " ") 31 | } 32 | 33 | func main() { 34 | // Verify that a subcommand has been provided 35 | if len(os.Args) < 2 { 36 | usage() 37 | os.Exit(1) 38 | } 39 | 40 | // Parse subcommand and call it with all remaining args 41 | switch os.Args[1] { 42 | case "scale-codec": 43 | ProcessScaleCodecCommand(os.Args[2:]) 44 | case "state-trie": 45 | ProcessStateTrieCommand(os.Args[2:]) 46 | case "host-api": 47 | host_api.ProcessHostApiCommand(os.Args[2:]) 48 | default: 49 | usage() 50 | os.Exit(1) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /adapters/gossamer/scale_codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | // this file provide a command line interface to call scale codec go library 19 | 20 | package main 21 | 22 | import ( 23 | "flag" 24 | "fmt" 25 | "github.com/ChainSafe/gossamer/pkg/scale" 26 | "os" 27 | ) 28 | 29 | func ProcessScaleCodecCommand(scale_codec_args []string) { 30 | //here we need to parse the args related to scale_codec 31 | 32 | // Subcommands 33 | encodeCommand := flag.NewFlagSet("encode", flag.ExitOnError) 34 | 35 | // encode subcommand flag pointers 36 | inputTextPtr := encodeCommand.String("input", "", "Text to parse. (Required)") 37 | 38 | // Verify that a subcommand has been provided 39 | // scale_codec_args[0] is the subcommand 40 | if len(scale_codec_args) < 1 { 41 | fmt.Println("encode or decode subcommand is required") 42 | os.Exit(1) 43 | } 44 | 45 | // Switch on the subcommand 46 | // Parse the flags for appropriate FlagSet 47 | // os.Args[2:] will be all arguments starting after the subcommand at os.Args[1] 48 | switch scale_codec_args[0] { 49 | case "encode": 50 | encodeCommand.Parse(scale_codec_args[1:]) 51 | default: 52 | flag.PrintDefaults() 53 | os.Exit(1) 54 | } 55 | 56 | // Check which subcommand was Parsed using the FlagSet.Parsed() function. Handle each case accordingly. 57 | // FlagSet.Parse() will evaluate to false if no flags were parsed 58 | if encodeCommand.Parsed() { 59 | // Required Flags 60 | if *inputTextPtr == "" { 61 | encodeCommand.PrintDefaults() 62 | os.Exit(1) 63 | } 64 | 65 | //Encode by scale codec and then base64 66 | encodedText, err := scale.Marshal(*inputTextPtr) 67 | if err != nil { 68 | os.Exit(1) 69 | } 70 | 71 | fmt.Printf("encoded %s: [", *inputTextPtr) 72 | csvHexPrinter(encodedText) 73 | fmt.Printf("]\n") 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /adapters/gossamer/shell.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem }: 2 | 3 | (builtins.getFlake "git+file:./../..").packages.${system}.gossamer-adapter.go-modules 4 | -------------------------------------------------------------------------------- /adapters/gossamer/state_trie.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | // this file provide a command line interface to call scale codec go library 19 | 20 | package main 21 | 22 | import ( 23 | "encoding/hex" 24 | "flag" 25 | "fmt" 26 | "io/ioutil" 27 | "log" 28 | "os" 29 | 30 | "github.com/ChainSafe/gossamer/lib/common" 31 | "github.com/ChainSafe/gossamer/lib/trie" 32 | 33 | "gopkg.in/yaml.v3" 34 | ) 35 | 36 | func ProcessStateTrieCommand(command_args []string) { 37 | 38 | // Subcommands 39 | stateRootCommand := flag.NewFlagSet("trie-root", flag.ExitOnError) 40 | 41 | // state-file subcommand flag pointers 42 | stateFilePtr := stateRootCommand.String("state-file", "", "YAML file containing the state") 43 | keysInHexPtr := stateRootCommand.Bool("keys-in-hex", false, "keys in the YAML file are treated as hex entries") 44 | 45 | // Verify that a subcommand has been provided 46 | if len(command_args) < 1 { 47 | fmt.Println("trie-root subcommand is required") 48 | os.Exit(1) 49 | } 50 | 51 | // Switch on the subcommand 52 | // Parse the flags for appropriate FlagSet 53 | switch command_args[0] { 54 | case "trie-root": 55 | stateRootCommand.Parse(command_args[1:]) 56 | 57 | case "insert-and-delete": 58 | stateRootCommand.Parse(command_args[1:]) 59 | default: 60 | flag.PrintDefaults() 61 | os.Exit(1) 62 | } 63 | 64 | // Check which subcommand was Parsed using the FlagSet.Parsed() function. Handle each case accordingly. 65 | // FlagSet.Parse() will evaluate to false if no flags were parsed 66 | if stateRootCommand.Parsed() { 67 | // Required Flags 68 | if *stateFilePtr == "" { 69 | stateRootCommand.PrintDefaults() 70 | os.Exit(1) 71 | } 72 | 73 | //Insert all (key, value) pairs in the YAML file into state trie. 74 | key_value_data := &KeyValueData{} 75 | var key_list [][]byte 76 | 77 | state_data_file, err := ioutil.ReadFile(*stateFilePtr) 78 | 79 | if err != nil { 80 | log.Fatal(err) 81 | } 82 | 83 | err = yaml.Unmarshal(state_data_file, &key_value_data) 84 | if err != nil { 85 | log.Fatal(err) 86 | } 87 | 88 | test_trie := trie.NewEmptyTrie() 89 | 90 | var trieHash common.Hash 91 | 92 | for i, key := range key_value_data.Keys { 93 | var keyBytes []byte 94 | 95 | if *keysInHexPtr { 96 | keyBytes, err = hex.DecodeString(key) 97 | if err != nil { 98 | log.Fatal(err) 99 | } 100 | } else { 101 | keyBytes = []byte(key) 102 | } 103 | 104 | key_list = append(key_list, keyBytes) 105 | test_trie.Put(keyBytes, []byte(key_value_data.Values[i])) 106 | 107 | if command_args[0] == "insert-and-delete" { 108 | trieHash, err = test_trie.Hash() 109 | if err != nil { 110 | log.Fatal(err) 111 | } 112 | fmt.Printf("state root: %x\n", trieHash[:]) 113 | } 114 | } 115 | 116 | if command_args[0] == "insert-and-delete" { 117 | for len(key_list) > 0 { 118 | key_index_to_drop := int(trieHash[0]) % len(key_list) 119 | test_trie.Delete(key_list[key_index_to_drop]) 120 | 121 | trieHash, err = test_trie.Hash() 122 | if err != nil { 123 | log.Fatal(err) 124 | } 125 | fmt.Printf("state root: %x\n", trieHash[:]) 126 | 127 | key_list = append(key_list[:key_index_to_drop], key_list[key_index_to_drop+1:]...) 128 | } 129 | 130 | } else { 131 | trieHash, err = test_trie.Hash() 132 | if err != nil { 133 | log.Fatal(err) 134 | } 135 | fmt.Printf("state root: %x\n", trieHash[:]) 136 | } 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /adapters/gossamer/util.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/hex" 5 | "fmt" 6 | ) 7 | 8 | //describing the (key, value) data format in the yaml file 9 | type KeyValueData struct { 10 | Keys []string `yaml:"keys"` 11 | Values []string `yaml:"values"` 12 | } 13 | 14 | func csvHexPrinter(encodedText []byte) { 15 | hexEncoded := make([]byte, hex.EncodedLen(len(encodedText))) 16 | hex.Encode(hexEncoded, encodedText) 17 | 18 | bihexcode := make([]byte, 2) 19 | for i, c := range hexEncoded { 20 | if i%2 == 0 { 21 | bihexcode[0] = c 22 | } else { 23 | bihexcode[1] = c 24 | if bihexcode[0] == '0' { 25 | fmt.Printf("%c", bihexcode[1]) 26 | } else { 27 | fmt.Printf("%s", bihexcode) 28 | } 29 | if i < len(hexEncoded)-1 { 30 | fmt.Printf(", ") 31 | } 32 | } 33 | } 34 | } 35 | 36 | func continuousHexPrinter(encodedText []byte) { 37 | hexEncoded := make([]byte, hex.EncodedLen(len(encodedText))) 38 | hex.Encode(hexEncoded, encodedText) 39 | fmt.Printf("%s", hexEncoded) 40 | } 41 | -------------------------------------------------------------------------------- /adapters/kagome/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | NamespaceIndentation: All 3 | BreakBeforeBinaryOperators: NonAssignment 4 | AlignOperands: true 5 | DerivePointerAlignment: false 6 | PointerAlignment: Right 7 | BinPackArguments: false 8 | BinPackParameters: false 9 | AllowShortFunctionsOnASingleLine: Empty 10 | IncludeBlocks: Preserve 11 | -------------------------------------------------------------------------------- /adapters/kagome/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /adapters/kagome/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 2 | # 3 | # This file is part of the Polkadot Test Suite. 4 | # 5 | # The Polkadot Test Suite is free software: you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # The Polkadot Test Suite is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with the Polkadot Test Suite. If not, see 17 | # . 18 | 19 | cmake_minimum_required(VERSION 3.12) 20 | 21 | 22 | # Setup toolchain (required by kagome and libp2p) 23 | set(CMAKE_TOOLCHAIN_FILE 24 | "${CMAKE_SOURCE_DIR}/cmake/Toolchain.cmake" 25 | CACHE FILEPATH "Default toolchain" 26 | ) 27 | 28 | # Propagate CMake build type to dependencies 29 | set( 30 | HUNTER_CONFIGURATION_TYPES "${CMAKE_BUILD_TYPE}" 31 | CACHE STRING "Hunter configuration type" 32 | ) 33 | 34 | # Enable upload to binary cache if username and password are supplied 35 | string(COMPARE EQUAL "$ENV{GITHUB_HUNTER_USERNAME}" "" UPLOAD_USER_EMPTY) 36 | string(COMPARE EQUAL "$ENV{GITHUB_HUNTER_TOKEN}" "" UPLOAD_TOKEN_EMPTY) 37 | 38 | if(UPLOAD_USER_EMPTY OR UPLOAD_TOKEN_EMPTY) 39 | set(HUNTER_RUN_UPLOAD NO CACHE BOOL "Upload to binary cache") 40 | else() 41 | set(HUNTER_RUN_UPLOAD YES CACHE BOOL "Upload to binary cache") 42 | endif() 43 | 44 | set( 45 | HUNTER_PASSWORDS_PATH "${CMAKE_SOURCE_DIR}/cmake/HunterPasswords.cmake" 46 | CACHE FILEPATH "Hunter passwords files" 47 | ) 48 | 49 | message(STATUS "Upload to binary cache: ${HUNTER_RUN_UPLOAD}") 50 | 51 | # Setup binary cache 52 | set( 53 | HUNTER_CACHE_SERVERS "https://github.com/w3f/hunter-binary-cache" 54 | CACHE STRING "Binary cache server" 55 | ) 56 | 57 | message(STATUS "Download from binary cache: ${HUNTER_USE_CACHE_SERVERS}") 58 | 59 | # Setup hunter 60 | include(cmake/HunterGate.cmake) 61 | HunterGate( 62 | URL "https://github.com/soramitsu/soramitsu-hunter/archive/refs/tags/v0.23.257-soramitsu38.zip" 63 | SHA1 "750757012e366941c9c677d8acbe5eebc6f71a63" 64 | FILEPATH "${CMAKE_SOURCE_DIR}/cmake/HunterConfig.cmake" 65 | ) 66 | 67 | set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ${HUNTER_ENABLED}) 68 | 69 | 70 | # General config 71 | project(kagome-adapter LANGUAGES CXX C) 72 | 73 | hunter_add_package(yaml-cpp) 74 | find_package(yaml-cpp REQUIRED) 75 | 76 | # Fix inconsistency between hunterized and upstream package (+ CMake oddity fix) 77 | if(NOT TARGET yaml-cpp) 78 | set_target_properties(yaml-cpp::yaml-cpp PROPERTIES IMPORTED_GLOBAL true) 79 | add_library(yaml-cpp ALIAS yaml-cpp::yaml-cpp) 80 | endif() 81 | 82 | hunter_add_package(Boost COMPONENTS program_options) 83 | find_package(Boost REQUIRED COMPONENTS program_options) 84 | 85 | hunter_add_package(scale) 86 | find_package(scale REQUIRED CONFIG) 87 | 88 | hunter_add_package(kagome) 89 | find_package(kagome REQUIRED CONFIG) 90 | 91 | get_target_property(kagome_INCLUDE_DIRS kagome::kagome INTERFACE_INCLUDE_DIRECTORIES) 92 | message(STATUS "Found kagome: ${kagome_INCLUDE_DIRS}") 93 | 94 | # Compile and link tester 95 | add_executable(kagome-adapter 96 | src/main.cpp 97 | src/assert.cpp 98 | src/scale_codec.cpp 99 | src/state_trie.cpp 100 | src/host_api.cpp 101 | src/host_api/helpers.cpp 102 | src/host_api/allocator.cpp 103 | src/host_api/crypto.cpp 104 | src/host_api/hashing.cpp 105 | src/host_api/trie.cpp 106 | src/host_api/storage.cpp 107 | src/host_api/child_storage.cpp 108 | ) 109 | 110 | target_link_libraries(kagome-adapter 111 | Boost::program_options 112 | yaml-cpp 113 | scale::scale 114 | kagome::blockchain 115 | kagome::binaryen_instance_environment_factory 116 | kagome::binaryen_module_factory 117 | kagome::bip39_provider 118 | kagome::chain_spec 119 | kagome::core_api 120 | kagome::crypto_store 121 | kagome::ed25519_provider 122 | kagome::hasher 123 | kagome::host_api_factory 124 | kagome::key_file_storage 125 | kagome::log_configurator 126 | kagome::offchain_persistent_storage 127 | kagome::offchain_worker_pool 128 | kagome::pbkdf2_provider 129 | kagome::runtime_properties_cache 130 | kagome::sr25519_provider 131 | kagome::storage_code_provider 132 | kagome::storage 133 | kagome::trie_storage_provider 134 | kagome::runtime_wavm 135 | ) 136 | 137 | 138 | # Install result 139 | include(GNUInstallDirs) 140 | 141 | install(TARGETS kagome-adapter 142 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 143 | ) 144 | -------------------------------------------------------------------------------- /adapters/kagome/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all configure build install enable-hunter disable-hunter enable-bincache disable-bincache enable-upload disable-upload version format clean 2 | 3 | all: install 4 | 5 | 6 | configure: 7 | cmake -DCMAKE_BUILD_TYPE=Release -S . -B build 8 | 9 | build: configure 10 | cmake --build build 11 | 12 | install: build 13 | cp build/kagome-adapter ../../bin/ 14 | 15 | 16 | enable-hunter: 17 | cmake -DHUNTER_ENABLED=YES -S . -B build 18 | 19 | disable-hunter: 20 | cmake -DHUNTER_ENABLED=NO -S . -B build 21 | 22 | 23 | enable-bincache: 24 | cmake -DHUNTER_USE_CACHE_SERVERS=YES -S . -B build 25 | 26 | disable-bincache: 27 | cmake -DHUNTER_USE_CACHE_SERVERS=NO -S . -B build 28 | 29 | 30 | enable-upload: 31 | cmake -DHUNTER_RUN_UPLOAD=YES -S . -B build 32 | 33 | disable-upload: 34 | cmake -DHUNTER_RUN_UPLOAD=NO -S . -B build 35 | 36 | 37 | version: 38 | @grep "github.com/soramitsu/kagome" cmake/HunterConfig.cmake | grep -o -E "[0-9a-f]{40}" 39 | 40 | 41 | format: 42 | find src -iname *.hpp -o -iname *.cpp | xargs clang-format -i 43 | 44 | 45 | clean: 46 | rm -rf build 47 | -------------------------------------------------------------------------------- /adapters/kagome/cmake/HunterConfig.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 2 | # 3 | # This file is part of the Polkadot Test Suite. 4 | # 5 | # The Polkadot Test Suite is free software: you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # The Polkadot Test Suite is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with the Polkadot Test Suite. If not, see 17 | # . 18 | 19 | # The version of kagome to be tested 20 | hunter_config(kagome 21 | GIT_SUBMODULE hosts/kagome 22 | CMAKE_ARGS TESTING=OFF 23 | ) 24 | 25 | # Extend local hunter config with kagome's settings 26 | include( 27 | ${CMAKE_SOURCE_DIR}/../../hosts/kagome/cmake/Hunter/config.cmake 28 | OPTIONAL RESULT_VARIABLE HUNTER_CONFIG_FOUND 29 | ) 30 | 31 | if(NOT HUNTER_CONFIG_FOUND) 32 | message(WARNING "Failed to include Hunter config of Kagome") 33 | endif() 34 | -------------------------------------------------------------------------------- /adapters/kagome/cmake/HunterPasswords.cmake: -------------------------------------------------------------------------------- 1 | 2 | hunter_upload_password( 3 | REPO_OWNER "w3f" 4 | REPO "hunter-binary-cache" 5 | USERNAME "$ENV{GITHUB_HUNTER_USERNAME}" 6 | PASSWORD "$ENV{GITHUB_HUNTER_TOKEN}" 7 | ) 8 | -------------------------------------------------------------------------------- /adapters/kagome/cmake/Toolchain.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 2 | # 3 | # This file is part of the Polkadot Test Suite. 4 | # 5 | # The Polkadot Test Suite is free software: you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # The Polkadot Test Suite is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with the Polkadot Test Suite. If not, see 17 | # . 18 | 19 | set(CMAKE_CXX_STANDARD 17) 20 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 21 | set(CMAKE_CXX_EXTENSIONS OFF) 22 | -------------------------------------------------------------------------------- /adapters/kagome/default.nix: -------------------------------------------------------------------------------- 1 | { polkadot-tests, stdenv, cmake, kagome-host, scale-codec-cpp, libyamlcpp }: 2 | 3 | stdenv.mkDerivation { 4 | pname = "kagome-adapter"; 5 | inherit (polkadot-tests) src version; 6 | 7 | sourceRoot = "source/adapters/kagome"; 8 | 9 | nativeBuildInputs = [ cmake ]; 10 | 11 | buildInputs = [ kagome-host scale-codec-cpp libyamlcpp ]; 12 | 13 | cmakeFlags = [ "-DHUNTER_ENABLED=FALSE" ]; 14 | } 15 | -------------------------------------------------------------------------------- /adapters/kagome/shell.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem }: 2 | 3 | (builtins.getFlake "git+file:./../..").packages.${system}.kagome-adapter 4 | -------------------------------------------------------------------------------- /adapters/kagome/src/assert.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #include "assert.hpp" 22 | 23 | #include 24 | 25 | namespace boost { 26 | 27 | void assertion_failed(char const *expr, 28 | char const *function, 29 | char const *file, 30 | long line) { 31 | std::stringstream ss; 32 | ss << "Assert inside function '" << function << "' in file '" << file 33 | << "' on line '" << line << "' when evaluating '" << expr << "'"; 34 | 35 | throw std::runtime_error(ss.str()); 36 | } 37 | 38 | void assertion_failed_msg(char const *expr, 39 | char const *msg, 40 | char const *function, 41 | char const *file, 42 | long line) { 43 | std::stringstream ss; 44 | ss << "Error inside function '" << function << "' in file '" << file 45 | << "' on line '" << line << "' when evaluating '" << expr 46 | << "': " << msg; 47 | 48 | throw std::runtime_error(ss.str()); 49 | } 50 | 51 | } // namespace boost 52 | -------------------------------------------------------------------------------- /adapters/kagome/src/assert.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | #define BOOST_ENABLE_ASSERT_HANDLER 26 | #include 27 | 28 | #include 29 | 30 | //! Custom exception to signal missing implementation 31 | struct NotImplemented : public std::runtime_error { 32 | NotImplemented() : std::runtime_error("Not implemented!") {} 33 | }; 34 | 35 | //! Helpers to print asserts and associated messages 36 | namespace boost { 37 | void assertion_failed(char const *expr, 38 | char const *function, 39 | char const *file, 40 | long line); 41 | 42 | void assertion_failed_msg(char const *expr, 43 | char const *msg, 44 | char const *function, 45 | char const *file, 46 | long line); 47 | } // namespace boost 48 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | #include "host_api/helpers.hpp" 27 | 28 | namespace host_api { 29 | 30 | struct CommandArgs { 31 | std::string runtime; 32 | std::string function; 33 | std::vector inputs; 34 | helpers::RuntimeEnvironment::Backend environment; 35 | }; 36 | 37 | CommandArgs extractArgs(int argc, char **argv); 38 | 39 | void processCommand(const CommandArgs &args); 40 | } // namespace host_api 41 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/allocator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #include "allocator.hpp" 22 | 23 | #include "helpers.hpp" 24 | 25 | #include 26 | 27 | namespace allocator { 28 | 29 | void malloc_free_version_1(helpers::RuntimeEnvironment environment, 30 | const std::vector &inputs) { 31 | // Parse inputs 32 | BOOST_ASSERT(inputs.size() == 1); 33 | 34 | const std::string_view value = inputs[0]; 35 | 36 | // The Wasm function tests both the allocation and freeing of the buffer 37 | auto result = environment.execute( 38 | "rtm_ext_allocator_malloc_version_1", value); 39 | 40 | BOOST_ASSERT_MSG(result.toString() == value, "Values are different"); 41 | 42 | std::cout << result.toString() << std::endl; 43 | } 44 | 45 | } // namespace allocator 46 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/allocator.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | #include "helpers.hpp" 27 | 28 | namespace allocator { 29 | 30 | // executes ext_allocator_malloc and ext_allocator_free tests 31 | void malloc_free_version_1(helpers::RuntimeEnvironment environment, 32 | const std::vector &inputs); 33 | 34 | } // namespace allocator 35 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/child_storage.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | #include "helpers.hpp" 27 | 28 | // TODO update and implement module 29 | namespace child_storage { 30 | 31 | // executes ext_default_child_storage_set_version_1 and 32 | // ext_default_child storage_get_version_1 test 33 | void set_get_version_1(helpers::RuntimeEnvironment environment, 34 | const std::vector &inputs); 35 | 36 | void read_version_1(helpers::RuntimeEnvironment environment, 37 | const std::vector &inputs); 38 | 39 | void clear_version_1(helpers::RuntimeEnvironment environment, 40 | const std::vector &inputs); 41 | 42 | void storage_kill_version_1(helpers::RuntimeEnvironment environment, 43 | const std::vector &inputs); 44 | 45 | void exists_version_1(helpers::RuntimeEnvironment environment, 46 | const std::vector &inputs); 47 | 48 | void clear_prefix_version_1(helpers::RuntimeEnvironment environment, 49 | const std::vector &inputs); 50 | 51 | void root_version_1(helpers::RuntimeEnvironment environment, 52 | const std::vector &inputs); 53 | 54 | void next_key_version_1(helpers::RuntimeEnvironment environment, 55 | const std::vector &inputs); 56 | 57 | } // namespace child_storage 58 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/crypto.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | #include "helpers.hpp" 26 | 27 | namespace crypto { 28 | 29 | // execute ext_crypto_ed25519_public_keys_version_1 test 30 | void ed25519_public_keys_version_1(helpers::RuntimeEnvironment &environment, 31 | const std::vector &inputs); 32 | 33 | // execute ext_crypto_ed25519_generate_version_1 test 34 | void ed25519_generate_version_1(helpers::RuntimeEnvironment &environment, 35 | const std::vector &inputs); 36 | 37 | // execute ext_crypto_ed25519_sign_version_1 test 38 | void ed25519_sign_version_1(helpers::RuntimeEnvironment &environment, 39 | const std::vector &inputs); 40 | 41 | // execute ext_crypto_ed25519_verify_version_1 test 42 | void ed25519_verify_version_1(helpers::RuntimeEnvironment environment, 43 | const std::vector &inputs); 44 | 45 | // execute ext_crypto_sr25519_public_keys_version_1 test 46 | void sr25519_public_keys_version_1(helpers::RuntimeEnvironment &environment, 47 | const std::vector &inputs); 48 | 49 | // execute ext_crypto_sr25519_generate_version_1 test 50 | void sr25519_generate_version_1(helpers::RuntimeEnvironment &environment, 51 | const std::vector &inputs); 52 | 53 | // execute ext_crypto_sr25519_sign_version_1 test 54 | void sr25519_sign_version_1(helpers::RuntimeEnvironment &environment, 55 | const std::vector &inputs); 56 | 57 | // execute ext_crypto_sr25519_verify_version_1 test 58 | void sr25519_verify_version_1(helpers::RuntimeEnvironment environment, 59 | const std::vector &inputs); 60 | 61 | } // namespace crypto 62 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/hashing.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #include "hashing.hpp" 22 | 23 | #include "helpers.hpp" 24 | 25 | #include 26 | #include 27 | 28 | namespace hashing { 29 | 30 | // execute hash function test by calling the select hash function 31 | // and target hash size with provided input. 32 | // 33 | // @param environment is the runtime environment to use 34 | // @param name is the name of the hash (e.g. blake2, keccak, sha2 or twox) 35 | // @param size is the expected size of the hash output 36 | // @param inputs to pass to the function 37 | void version_1(helpers::RuntimeEnvironment &environment, 38 | const std::string_view name, 39 | uint32_t size, 40 | const std::vector &inputs) { 41 | // Parse inputs 42 | BOOST_ASSERT(inputs.size() == 1); 43 | 44 | const std::string_view data = inputs[0]; 45 | 46 | // Call hash function 47 | std::stringstream function; 48 | function << "rtm_ext_hashing_" << name << "_" << size * 8 << "_version_1"; 49 | 50 | auto hash = environment.execute(function.str(), data); 51 | 52 | BOOST_ASSERT_MSG(hash.size() == size, "Incorrect hash size."); 53 | 54 | // Print result 55 | std::cout << hash.toHex() << std::endl; 56 | } 57 | 58 | void blake2_128_version_1(helpers::RuntimeEnvironment &environment, 59 | const std::vector &inputs) { 60 | version_1(environment, "blake2", 16, inputs); 61 | } 62 | 63 | void blake2_256_version_1(helpers::RuntimeEnvironment &environment, 64 | const std::vector &inputs) { 65 | version_1(environment, "blake2", 32, inputs); 66 | } 67 | 68 | void keccak_256_version_1(helpers::RuntimeEnvironment &environment, 69 | const std::vector &inputs) { 70 | version_1(environment, "keccak", 32, inputs); 71 | } 72 | 73 | void sha2_256_version_1(helpers::RuntimeEnvironment &environment, 74 | const std::vector &inputs) { 75 | version_1(environment, "sha2", 32, inputs); 76 | } 77 | 78 | void twox_64_version_1(helpers::RuntimeEnvironment &environment, 79 | const std::vector &inputs) { 80 | version_1(environment, "twox", 8, inputs); 81 | } 82 | 83 | void twox_128_version_1(helpers::RuntimeEnvironment &environment, 84 | const std::vector &inputs) { 85 | version_1(environment, "twox", 16, inputs); 86 | } 87 | 88 | void twox_256_version_1(helpers::RuntimeEnvironment &environment, 89 | const std::vector &inputs) { 90 | version_1(environment, "twox", 32, inputs); 91 | } 92 | 93 | } // namespace hashing 94 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/hashing.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | #include "helpers.hpp" 27 | 28 | namespace hashing { 29 | 30 | void blake2_128_version_1(helpers::RuntimeEnvironment &environment, 31 | const std::vector &inputs); 32 | 33 | void blake2_256_version_1(helpers::RuntimeEnvironment &environment, 34 | const std::vector &inputs); 35 | 36 | void keccak_256_version_1(helpers::RuntimeEnvironment &environment, 37 | const std::vector &inputs); 38 | 39 | void sha2_256_version_1(helpers::RuntimeEnvironment &environment, 40 | const std::vector &inputs); 41 | 42 | void twox_64_version_1(helpers::RuntimeEnvironment &environment, 43 | const std::vector &inputs); 44 | 45 | void twox_128_version_1(helpers::RuntimeEnvironment &environment, 46 | const std::vector &inputs); 47 | 48 | void twox_256_version_1(helpers::RuntimeEnvironment &environment, 49 | const std::vector &inputs); 50 | 51 | } // namespace hashing 52 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/helpers.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "../assert.hpp" 24 | 25 | #include 26 | 27 | // Needs to be included first to work around kagome bug 28 | #include 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | namespace helpers { 36 | 37 | using kagome::common::Buffer; 38 | using MaybeBuffer = std::optional; 39 | 40 | using kagome::runtime::MemoryProvider; 41 | using kagome::runtime::ModuleInstance; 42 | using kagome::runtime::PtrSize; 43 | 44 | // Default path of runtime 45 | extern const char *DEFAULT_RUNTIME_PATH; 46 | 47 | class RuntimeEnvironment { 48 | public: 49 | // Available backends 50 | enum class Backend { 51 | Binaryen, 52 | WAVM, 53 | }; 54 | 55 | // Backend used by default 56 | static const Backend DEFAULT_BACKEND; 57 | 58 | // Initialize a new runtime environment 59 | RuntimeEnvironment(const std::string path = DEFAULT_RUNTIME_PATH, 60 | Backend backend = DEFAULT_BACKEND); 61 | 62 | // Get type of environment 63 | Backend getBackend() const; 64 | 65 | // Call function with provided arguments 66 | template 67 | ReturnType execute(std::string_view name, Args &&...args) { 68 | auto &memory = memory_provider_->getCurrentMemory().value().get(); 69 | 70 | Buffer encoded_args{}; 71 | if constexpr (sizeof...(args) > 0) { 72 | auto res = scale::encode(std::forward(args)...); 73 | BOOST_ASSERT_MSG(res.has_value(), res.error().message().data()); 74 | encoded_args.put(std::move(res.value())); 75 | } 76 | 77 | auto result = module_instance_->callExportFunction(name, encoded_args); 78 | BOOST_ASSERT_MSG(result.has_value(), result.error().message().data()); 79 | 80 | auto reset = module_instance_->resetEnvironment(); 81 | BOOST_ASSERT_MSG(reset.has_value(), reset.error().message().data()); 82 | 83 | if constexpr (not std::is_void_v) { 84 | auto res = scale::decode( 85 | memory.loadN(result.value().ptr, result.value().size)); 86 | BOOST_ASSERT_MSG(res.has_value(), res.error().message().data()); 87 | return res.value(); 88 | } 89 | } 90 | 91 | private: 92 | // Backend used by the environment 93 | Backend backend_; 94 | 95 | // Main objects used to execute calls 96 | std::shared_ptr module_instance_; 97 | std::shared_ptr memory_provider_; 98 | }; 99 | } // namespace helpers 100 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/storage.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | #include "helpers.hpp" 27 | 28 | namespace storage { 29 | 30 | // executes ext_storage_init test 31 | void test_init(helpers::RuntimeEnvironment &environment, 32 | const std::vector &inputs); 33 | 34 | // executes ext_storage_set_version_1/ext_storage_get_version_1 test 35 | void set_get_version_1(helpers::RuntimeEnvironment &environment, 36 | const std::vector &inputs); 37 | 38 | // executes ext_storage_read_version_1 test 39 | void read_version_1(helpers::RuntimeEnvironment &environment, 40 | const std::vector &inputs); 41 | 42 | // executes ext_storage_clear_version_1 test 43 | void clear_version_1(helpers::RuntimeEnvironment &environment, 44 | const std::vector &inputs); 45 | 46 | // executes ext_storage_exists_version_1 test 47 | void exists_version_1(helpers::RuntimeEnvironment &environment, 48 | const std::vector &inputs); 49 | 50 | // executes ext_storage_clear_prefix_version_1 test 51 | void clear_prefix_version_1(helpers::RuntimeEnvironment &environment, 52 | const std::vector &inputs); 53 | 54 | // executes ext_storage_append_version_1 test 55 | void append_version_1(helpers::RuntimeEnvironment &environment, 56 | const std::vector &inputs); 57 | 58 | // executes ext_storage_root_version_1 test 59 | void root_version_1(helpers::RuntimeEnvironment &environment, 60 | const std::vector &inputs); 61 | 62 | // executes ext_storage_next_key_version_1 test 63 | void next_key_version_1(helpers::RuntimeEnvironment &environment, 64 | const std::vector &inputs); 65 | 66 | } // namespace storage 67 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/trie.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #include "trie.hpp" 22 | 23 | #include "helpers.hpp" 24 | 25 | #include 26 | 27 | #include 28 | 29 | namespace trie { 30 | 31 | void blake2_256_ordered_root_version_1( 32 | helpers::RuntimeEnvironment &environment, 33 | const std::vector &inputs) { 34 | // Parse inputs 35 | BOOST_ASSERT(inputs.size() == 3); 36 | 37 | const std::string_view value1 = inputs[0]; 38 | const std::string_view value2 = inputs[1]; 39 | const std::string_view value3 = inputs[2]; 40 | 41 | // Compute ordered trie root 42 | auto hash = environment.execute( 43 | "rtm_ext_trie_blake2_256_ordered_root_version_1", 44 | std::vector{value1, value2, value3}); 45 | 46 | // Print result 47 | std::cout << hash.toHex() << std::endl; 48 | } 49 | 50 | void blake2_256_root_version_1(helpers::RuntimeEnvironment &environment, 51 | const std::vector &inputs) { 52 | // Parse inputs 53 | BOOST_ASSERT(inputs.size() == 6); 54 | 55 | const std::string_view key1 = inputs[0]; 56 | const std::string_view value1 = inputs[1]; 57 | 58 | const std::string_view key2 = inputs[2]; 59 | const std::string_view value2 = inputs[3]; 60 | 61 | const std::string_view key3 = inputs[4]; 62 | const std::string_view value3 = inputs[5]; 63 | 64 | // Compute trie root 65 | auto hash = environment.execute( 66 | "rtm_ext_trie_blake2_256_root_version_1", 67 | std::vector{ 68 | std::pair{key1, value1}, 69 | std::pair{key2, value2}, 70 | std::pair{key3, value3}, 71 | }); 72 | 73 | // Print result 74 | std::cout << hash.toHex() << std::endl; 75 | } 76 | } // namespace trie 77 | -------------------------------------------------------------------------------- /adapters/kagome/src/host_api/trie.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | #include "helpers.hpp" 26 | 27 | namespace trie { 28 | 29 | // executes ext_trie_blake2_256_ordered_root_version_1 test 30 | void blake2_256_ordered_root_version_1( 31 | helpers::RuntimeEnvironment &environment, 32 | const std::vector &inputs); 33 | 34 | // executes ext_trie_blake2_256_root_version_1 test 35 | void blake2_256_root_version_1(helpers::RuntimeEnvironment &environment, 36 | const std::vector &inputs); 37 | 38 | } // namespace trie 39 | -------------------------------------------------------------------------------- /adapters/kagome/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #include "assert.hpp" 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | // Needs to be included first to work around kagome bug 29 | #include 30 | 31 | #include 32 | 33 | #include "subcommand.hpp" 34 | 35 | #include "host_api.hpp" 36 | #include "scale_codec.hpp" 37 | #include "state_trie.hpp" 38 | 39 | #include 40 | 41 | /** 42 | * Implementation of Polkadot Host API, SCALE codec and Merkle-Patricia 43 | * Tree compatibility tests 44 | */ 45 | int main(int argc, char **argv) { 46 | try { 47 | // Initialize logging system 48 | auto loglevel = kagome::log::Level::ERROR; 49 | if (argc > 1 and argv[1] == std::string_view("--verbose")) { 50 | loglevel = kagome::log::Level::DEBUG; 51 | argc--; 52 | argv++; 53 | } 54 | 55 | auto config = std::make_shared(loglevel); 56 | auto logger = std::make_shared(config); 57 | 58 | auto result = logger->configure(); 59 | auto e0 = "Failed to configure logger: " + result.message; 60 | BOOST_ASSERT_MSG(!result.has_error, e0.data()); 61 | 62 | kagome::log::setLoggingSystem(logger); 63 | 64 | // Initialize subcommand router with known commands 65 | SubcommandRouter router; 66 | router.addSubcommand("scale-codec", [](int argc, char **argv) { 67 | processScaleCodecCommand(extractScaleArgs(argc, argv)); 68 | }); 69 | router.addSubcommand("state-trie", [](int argc, char **argv) { 70 | processTrieCommand(extractTrieArgs(argc, argv)); 71 | }); 72 | router.addSubcommand("host-api", [](int argc, char **argv) { 73 | host_api::processCommand(host_api::extractArgs(argc, argv)); 74 | }); 75 | 76 | // Check if subcommand is provided 77 | std::string commands_list = "Valid subcommands are: "; 78 | for (auto &&name : router.collectSubcommandNames()) { 79 | commands_list += name; 80 | commands_list += " "; 81 | } 82 | 83 | auto e1 = "Subcommand is not provided\n" + commands_list; 84 | BOOST_ASSERT_MSG(argc > 1, e1.data()); 85 | 86 | // Run subcommand 87 | auto e2 = "Invalid subcommand\n" + commands_list; 88 | BOOST_VERIFY_MSG(router.executeSubcommand(argv[1], argc - 1, argv + 1), 89 | e2.data()); 90 | 91 | } catch (const NotImplemented &e) { 92 | return EOPNOTSUPP; 93 | } catch (const std::exception &e) { 94 | std::cerr << "Exception: " << e.what() << std::endl; 95 | return EXIT_FAILURE; 96 | } 97 | 98 | return EXIT_SUCCESS; 99 | } 100 | -------------------------------------------------------------------------------- /adapters/kagome/src/scale_codec.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #include "scale_codec.hpp" 22 | 23 | #include "assert.hpp" 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include "subcommand.hpp" 31 | 32 | #include 33 | 34 | namespace po = boost::program_options; 35 | 36 | ScaleCommandArgs extractScaleArgs(int argc, char **argv) { 37 | po::options_description desc("SCALE codec related tests\nAllowed options:"); 38 | boost::optional subcommand; 39 | boost::optional input; 40 | // clang-format off 41 | desc.add_options() 42 | ("help", "produce help message") 43 | ("subcommand", po::value(&subcommand)->required(), "specify a subcommand") 44 | ("input,i", po::value(&input)->required(), "the string to be encoded"); 45 | // clang-format on 46 | 47 | po::positional_options_description pd; 48 | pd.add("subcommand", 1); 49 | 50 | po::variables_map vm; 51 | po::store( 52 | po::command_line_parser(argc, argv).options(desc).positional(pd).run(), 53 | vm); 54 | po::notify(vm); 55 | 56 | BOOST_ASSERT_MSG(subcommand, "Subcommand is not stated"); 57 | BOOST_ASSERT_MSG(input, "Input string is not provided"); 58 | 59 | return ScaleCommandArgs{.subcommand = *subcommand, .input = *input}; 60 | } 61 | 62 | void processScaleCodecCommand(ScaleCommandArgs args) { 63 | SubcommandRouter router; 64 | router.addSubcommand("encode", [](std::string input) { 65 | auto res = scale::encode(input); 66 | BOOST_ASSERT_MSG(res, "Encode error"); 67 | std::cout << "encoded " << input << ": ["; 68 | bool first = true; 69 | for (auto byte : res.value()) { 70 | if (not first) { 71 | std::cout << ", "; 72 | } else { 73 | first = false; 74 | } 75 | std::cout << std::hex << (int)byte; 76 | } 77 | std::cout << "]\n"; 78 | }); 79 | 80 | BOOST_VERIFY_MSG(router.executeSubcommand(args.subcommand, args.input), 81 | "Invalid subcommand"); 82 | } 83 | -------------------------------------------------------------------------------- /adapters/kagome/src/scale_codec.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | // arguments for SCALE tests 26 | struct ScaleCommandArgs { 27 | std::string subcommand; 28 | std::string input; 29 | }; 30 | 31 | // parses CLI input 32 | ScaleCommandArgs extractScaleArgs(int argc, char **argv); 33 | 34 | // executes SCALE tests according to provided args 35 | void processScaleCodecCommand(ScaleCommandArgs args); 36 | -------------------------------------------------------------------------------- /adapters/kagome/src/state_trie.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | // Trie test args 26 | struct TrieCommandArgs { 27 | std::string subcommand; 28 | bool keys_in_hex; 29 | bool values_in_hex; 30 | bool log_trie; 31 | std::string state_file_name; 32 | }; 33 | 34 | // parses CLI input 35 | TrieCommandArgs extractTrieArgs(int argc, char **argv); 36 | 37 | // executes Trie tests according to provided args 38 | void processTrieCommand(const TrieCommandArgs &args); 39 | -------------------------------------------------------------------------------- /adapters/kagome/src/subcommand.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Web 3.0 Technologies Foundation 3 | * 4 | * This file is part of the Polkadot Test Suite. 5 | * 6 | * The Polkadot Test Suite is free software: you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * The Polkadot Test Suite is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Polkadot Test Suite. If not, see 18 | * . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | /** 28 | * A dictionary command_name -> functor 29 | * Utility class to store functors associated with some names and 30 | * execute them using the names 31 | * @tparam Args input arguments of a stored functor 32 | */ 33 | template 34 | class SubcommandRouter { 35 | public: 36 | using HandlerMap = std::map>; 37 | 38 | /** Default constructor to add subcommands via addSubcommand. 39 | */ 40 | SubcommandRouter() = default; 41 | 42 | /** Constructor to allow static initialization. 43 | * @param map intial list of handlers to start with 44 | */ 45 | SubcommandRouter(HandlerMap &&inital) : handlers(std::move(inital)) {} 46 | 47 | /** 48 | * @param name name of subcommand to add 49 | * @param handler callback to handle execution of subcommand 50 | */ 51 | void addSubcommand(std::string name, std::function handler) { 52 | handlers[std::move(name)] = std::move(handler); 53 | } 54 | 55 | /** 56 | * @return names of all stored subcommands 57 | */ 58 | std::list collectSubcommandNames() const { 59 | std::list names; 60 | for (auto &[key, value] : handlers) { 61 | names.push_back(key); 62 | } 63 | return names; 64 | } 65 | 66 | /** 67 | * @tparam FArgs input arguments of the called functor 68 | * @param name of the functor to call 69 | * @param args that would be passed to the functor 70 | * @return true if a functor with the corresponding name was found, false 71 | * otherwise 72 | */ 73 | template 74 | bool executeSubcommand(const std::string &name, FArgs &&...args) { 75 | if (handlers.find(name) != handlers.end()) { 76 | handlers.at(name)(std::forward(args)...); 77 | return true; 78 | } 79 | return false; 80 | } 81 | 82 | private: 83 | HandlerMap handlers; 84 | }; 85 | -------------------------------------------------------------------------------- /adapters/substrate/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /adapters/substrate/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "substrate-adapter" 3 | version = "0.9.31-f0e1ed0" 4 | edition = "2021" 5 | rust-version = "1.64.0" 6 | 7 | [dependencies] 8 | base64 = "0.13" 9 | clap = { version="3", features = ["cargo"] } 10 | data-encoding = "2.3" 11 | hex = "0.4" 12 | serde_yaml = "0.8" 13 | 14 | # scale-codec 15 | parity-scale-codec = "3.0" 16 | 17 | # state-trie 18 | reference-trie = "0.25" 19 | keccak-hasher = "0.15" 20 | memory-db = "0.30" 21 | hash-db = "0.15" 22 | trie-db = "0.23" 23 | trie-root = "0.17" 24 | 25 | # host-api 26 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } 27 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } 28 | sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } 29 | sc-executor-common = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } 30 | sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } 31 | sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } 32 | -------------------------------------------------------------------------------- /adapters/substrate/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all build install build-expmem install-expmem version clean 2 | 3 | all: install 4 | 5 | build: 6 | cargo build --release 7 | 8 | install: build 9 | cp target/release/substrate-adapter ../../bin/ 10 | 11 | 12 | build-expmem: 13 | cargo build --features export-memory --release 14 | 15 | install-expmem: build-expmem 16 | cp target/release/substrate-adapter ../../bin/substrate-adapter-expmem 17 | 18 | 19 | version: 20 | @cargo metadata --format-version 1 | jq '.packages[] | select(.name=="sp-core").id' | cut -d' ' -f2 21 | 22 | format: 23 | cargo fmt 24 | 25 | clean: 26 | rm -rf target 27 | -------------------------------------------------------------------------------- /adapters/substrate/default.nix: -------------------------------------------------------------------------------- 1 | { polkadot-tests, lib, naersk }: 2 | 3 | naersk.buildPackage { 4 | name = "substrate-adapter"; 5 | inherit (polkadot-tests) version; 6 | 7 | src = "${polkadot-tests.src}/adapters/substrate"; 8 | } 9 | -------------------------------------------------------------------------------- /adapters/substrate/shell.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem }: 2 | 3 | (builtins.getFlake "git+file:./../..").devShells.${system}.substrate 4 | -------------------------------------------------------------------------------- /adapters/substrate/src/host_api/allocator.rs: -------------------------------------------------------------------------------- 1 | use crate::host_api::utils::{str, ParsedInput, Runtime}; 2 | use parity_scale_codec::Encode; 3 | 4 | /// The Wasm function tests both the allocation and freeing of the buffer 5 | pub fn ext_allocator_malloc_version_1(mut rtm: Runtime, input: ParsedInput) { 6 | // Parse inputs 7 | let value = input.get(0); 8 | 9 | // Get invalid key 10 | let res = rtm.call_and_decode::>("rtm_ext_allocator_malloc_version_1", &value.encode()); 11 | assert_eq!(res, value); 12 | 13 | println!("{}", str(&res)); 14 | } 15 | 16 | pub fn ext_allocator_free_version_1(rtm: Runtime, input: ParsedInput) { 17 | ext_allocator_malloc_version_1(rtm, input) 18 | } 19 | -------------------------------------------------------------------------------- /adapters/substrate/src/host_api/hashing.rs: -------------------------------------------------------------------------------- 1 | use crate::host_api::utils::{ParsedInput, Runtime}; 2 | use parity_scale_codec::Encode; 3 | 4 | pub fn ext_hashing_version_1(mut rtm: Runtime, func: &str, input: ParsedInput) { 5 | let data = input.get(0); 6 | 7 | let hash = rtm.call_and_decode::>( 8 | &["rtm_ext_hashing_", func, "_version_1"].join(""), 9 | &(data).encode(), 10 | ); 11 | 12 | println!("{}", hex::encode(hash)); 13 | } 14 | -------------------------------------------------------------------------------- /adapters/substrate/src/host_api/trie.rs: -------------------------------------------------------------------------------- 1 | use crate::host_api::utils::{ParsedInput, Runtime}; 2 | use parity_scale_codec::Encode; 3 | 4 | pub fn ext_trie_blake2_256_root_version_1(mut rtm: Runtime, input: ParsedInput) { 5 | // Parse input 6 | let key1 = input.get(0); 7 | let value1 = input.get(1); 8 | let key2 = input.get(2); 9 | let value2 = input.get(3); 10 | let key3 = input.get(4); 11 | let value3 = input.get(5); 12 | 13 | let trie = vec![(key1, value1), (key2, value2), (key3, value3)]; 14 | 15 | // Get valid key 16 | let res = 17 | rtm.call_and_decode::>("rtm_ext_trie_blake2_256_root_version_1", &(trie).encode()); 18 | 19 | println!("{}", hex::encode(res)); 20 | } 21 | 22 | pub fn ext_trie_blake2_256_ordered_root_version_1(mut rtm: Runtime, input: ParsedInput) { 23 | // Parse input 24 | let value1 = input.get(0); 25 | let value2 = input.get(1); 26 | let value3 = input.get(2); 27 | 28 | let trie = vec![value1, value2, value3]; 29 | 30 | // Get valid key 31 | let res = rtm.call_and_decode::>( 32 | "rtm_ext_trie_blake2_256_ordered_root_version_1", 33 | &(trie).encode(), 34 | ); 35 | 36 | println!("{}", hex::encode(res)); 37 | } 38 | -------------------------------------------------------------------------------- /adapters/substrate/src/host_api/utils.rs: -------------------------------------------------------------------------------- 1 | use clap::Values; 2 | 3 | use parity_scale_codec::Decode; 4 | use sp_core::{offchain::testing::TestOffchainExt, offchain::OffchainDbExt, Blake2Hasher}; 5 | use sc_executor::{WasmExecutionMethod, WasmExecutor, WasmtimeInstantiationStrategy}; 6 | use sc_executor_common::runtime_blob::RuntimeBlob; 7 | use sp_io::SubstrateHostFunctions; 8 | use sp_keystore::{testing::KeyStore, KeystoreExt}; 9 | use sp_state_machine::TestExternalities; 10 | use std::fs::File; 11 | use std::io::Read; 12 | use std::path::Path; 13 | use std::sync::Arc; 14 | 15 | pub fn str<'a>(input: &'a [u8]) -> &'a str { 16 | std::str::from_utf8(input).unwrap() 17 | } 18 | 19 | // Helper to pass and parse function inputs 20 | pub struct ParsedInput<'a>(Vec<&'a str>); 21 | 22 | impl<'a> ParsedInput<'a> { 23 | pub fn get(&self, index: usize) -> &[u8] { 24 | if let Some(ret) = self.0.get(index) { 25 | ret.as_bytes() 26 | } else { 27 | panic!("failed to get index, wrong input data provided for the test function"); 28 | } 29 | } 30 | pub fn get_u32(&self, index: usize) -> u32 { 31 | if let Some(ret) = self.0.get(index) { 32 | ret.parse().expect("failed to parse parameter as u32") 33 | } else { 34 | panic!("failed to get index, wrong input data provided for the test function"); 35 | } 36 | } 37 | } 38 | 39 | impl<'a> From> for ParsedInput<'a> { 40 | fn from(input: Values<'a>) -> Self { 41 | ParsedInput(input.collect()) 42 | } 43 | } 44 | 45 | impl<'a> From>> for ParsedInput<'a> { 46 | fn from(input: Option>) -> Self { 47 | match input { 48 | Some(v) => ParsedInput(v.collect()), 49 | None => ParsedInput(Vec::new()), 50 | } 51 | } 52 | } 53 | 54 | // Helpers to configure and call into runtime environment 55 | pub struct Runtime { 56 | blob: Vec, 57 | ext: TestExternalities, 58 | method: WasmExecutionMethod, 59 | } 60 | 61 | impl Runtime { 62 | pub fn new(path: &Path) -> Self { 63 | let mut wasm_binary = Vec::new(); 64 | 65 | let _ = File::open(path) 66 | .unwrap() 67 | .read_to_end(&mut wasm_binary) 68 | .unwrap(); 69 | 70 | Runtime { 71 | blob: wasm_binary, 72 | ext: TestExternalities::default(), 73 | method: WasmExecutionMethod::Interpreted, 74 | } 75 | } 76 | 77 | pub fn using_wasmi(mut self) -> Self { 78 | self.method = WasmExecutionMethod::Interpreted; 79 | self 80 | } 81 | pub fn using_wasmtime(mut self) -> Self { 82 | self.method = WasmExecutionMethod::Compiled { 83 | instantiation_strategy: WasmtimeInstantiationStrategy::RecreateInstance, 84 | }; 85 | self 86 | } 87 | 88 | pub fn with_keystore(mut self) -> Self { 89 | let key_store = KeystoreExt(Arc::new(KeyStore::new())); 90 | self.ext.register_extension(key_store); 91 | self 92 | } 93 | pub fn with_offchain(mut self) -> Self { 94 | let (offchain, _) = TestOffchainExt::new(); 95 | self.ext.register_extension(OffchainDbExt::new(offchain)); 96 | self 97 | } 98 | 99 | pub fn call(&mut self, func: &str, args: &[u8]) -> Vec { 100 | let mut extext = self.ext.ext(); 101 | 102 | WasmExecutor::::new( 103 | self.method, 104 | Some(8), // heap_pages 105 | 8, // max_runtime_instances 106 | None, // cache_path 107 | 2, // runtime_cache_size 108 | ) 109 | .uncached_call( 110 | RuntimeBlob::uncompress_if_needed(&self.blob[..]).unwrap(), 111 | &mut extext, 112 | false, // allow_missing_host_functions 113 | func, 114 | args, 115 | ) 116 | .unwrap() 117 | } 118 | pub fn call_and_decode(&mut self, func: &str, args: &[u8]) -> T { 119 | Decode::decode(&mut self.call(func, args).as_slice()) 120 | .expect("Failed to decode returned SCALE data") 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /adapters/substrate/src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Polkadot Host Test Suite. If not, see . 17 | 18 | ///This file is an interface to run various Polkadot Host functions 19 | 20 | use clap::command; 21 | 22 | // Fixture sub-adapters 23 | mod host_api; 24 | mod scale_codec; 25 | mod state_trie; 26 | 27 | fn main() { 28 | let matches = command!() 29 | .subcommand_required(true) 30 | .subcommands( vec![ 31 | host_api::get_subcommand(), 32 | scale_codec::get_subcommand(), 33 | state_trie::get_subcommand(), 34 | ]) 35 | .get_matches(); 36 | 37 | match matches.subcommand() { 38 | Some(("host-api", m)) => host_api::process_subcommand(m), 39 | Some(("scale-codec", m)) => scale_codec::process_subcommand(m), 40 | Some(("state-trie", m)) => state_trie::process_subcommand(m), 41 | _ => unimplemented!("Unknown command"), 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /adapters/substrate/src/scale_codec.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Polkadot Host Test Suite. If not, see . 17 | 18 | ///This file is an interface to run Parity implementation of SCALE codec. 19 | 20 | use clap::{Arg, ArgMatches, Command}; 21 | use clap::builder::PossibleValuesParser; 22 | 23 | use parity_scale_codec::Encode; 24 | 25 | // Command line processing 26 | 27 | pub fn get_subcommand() -> Command<'static> { 28 | return Command::new("scale-codec") 29 | .about("Scale Codec related tests") 30 | .arg(Arg::new("function") 31 | .index(1) 32 | .required(true) 33 | .value_parser(PossibleValuesParser::new(["encode"]))) 34 | .arg(Arg::new("input") 35 | .help("the input to be encoded") 36 | .long("input") 37 | .required(true) 38 | .short('i') 39 | .takes_value(true) 40 | .value_name("INPUT_VALUE")); 41 | } 42 | 43 | pub fn process_subcommand(matches: &ArgMatches) { 44 | let function = matches.get_one::("function").unwrap(); 45 | 46 | let input = matches.get_one::("input").unwrap(); 47 | 48 | match function.as_str() { 49 | "encode" => encode(input), 50 | _ => unimplemented!("Unknown function"), 51 | } 52 | } 53 | 54 | // Test functions 55 | 56 | fn encode(value: &String) { 57 | println!("encoded {}: {:x?}", value, value.encode()); 58 | } 59 | -------------------------------------------------------------------------------- /adapters/substrate/src/state_trie.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Web3 Technologies Foundation 2 | 3 | // This file is part of Polkadot Host Test Suite 4 | 5 | // Polkadot Host Test Suite is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // Polkadot Host Tests is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | // You should have received a copy of the GNU General Public License 16 | // along with Foobar. If not, see . 17 | 18 | ///This file is an interface to run Parity implementation of state trie used in Polkadot Host. 19 | 20 | use std::path::PathBuf; 21 | 22 | use std::collections::BTreeMap; 23 | 24 | 25 | use clap::{Arg, ArgMatches, Command, value_parser}; 26 | use clap::builder::PossibleValuesParser; 27 | 28 | use memory_db::{HashKey, MemoryDB}; 29 | 30 | use reference_trie::GenericNoExtensionLayout; 31 | use reference_trie::ReferenceTrieStreamNoExt as ReferenceTrieStream; 32 | 33 | use sp_core::Blake2Hasher; 34 | 35 | use trie_db::TrieMut; 36 | use trie_root::trie_root_no_extension; 37 | 38 | 39 | pub fn get_subcommand() -> Command<'static> { 40 | return Command::new("state-trie") 41 | .about("State Trie related tests") 42 | .arg(Arg::new("function") 43 | .index(1) 44 | .required(true) 45 | .value_parser(PossibleValuesParser::new(["trie-root", "insert-and-delete"]))) 46 | .arg(Arg::new("state-file") 47 | .long("state-file") 48 | .required(true) 49 | .short('i') 50 | .takes_value(true) 51 | .value_name("INPUT_FILE") 52 | .value_parser(value_parser!(PathBuf))) 53 | .arg(Arg::new("keys-in-hex") 54 | .action(clap::ArgAction::SetTrue) 55 | .help("interpret all keys in the state file as hex encoded") 56 | .long("keys-in-hex")) 57 | .arg(Arg::new("values-in-hex") 58 | .action(clap::ArgAction::SetTrue) 59 | .help("interpret all values in the state file as hex encoded") 60 | .long("values-in-hex")); 61 | } 62 | 63 | /// Create TrieTester and read its data according to the command line arg 64 | pub fn process_subcommand(matches: &ArgMatches) { 65 | 66 | let state_file = matches.get_one::("state-file").unwrap(); 67 | 68 | let keys_in_hex = matches.get_one::("keys-in-hex").unwrap(); 69 | let values_in_hex = matches.get_one::("values-in-hex").unwrap(); 70 | 71 | let mut tester = TrieTester::new(state_file, keys_in_hex, values_in_hex); 72 | 73 | 74 | let function = matches.get_one::("function").unwrap(); 75 | 76 | match function.as_str() { 77 | "trie-root" => tester.compute_state_root(), 78 | "insert-and-delete" => tester.insert_and_delete_test(), 79 | _ => unimplemented!("Unknown function"), 80 | } 81 | } 82 | 83 | ///An object to perform various tests on a trie 84 | pub struct TrieTester { 85 | keys: Vec>, 86 | values: Vec>, 87 | } 88 | 89 | impl TrieTester { 90 | 91 | /// Read a yaml state file containig key value pairs and return a list of entries 92 | pub fn new(state_file_path: &PathBuf, hex_keys: &bool, hex_values: &bool) -> Self { 93 | // Attempt to open state file 94 | let state_file = std::fs::File::open(state_file_path).unwrap(); 95 | 96 | // We are deserializing the state data in a BTree 97 | let key_value_map: BTreeMap> = serde_yaml::from_reader(state_file).unwrap(); 98 | 99 | TrieTester { 100 | keys: key_value_map["keys"] 101 | .iter() 102 | .map(|k| { 103 | if *hex_keys { 104 | hex::decode(k).expect("Decoding failed") 105 | } else { 106 | k.clone().into_bytes() 107 | } 108 | }) 109 | .collect(), 110 | values: key_value_map["values"] 111 | .iter() 112 | .map(|v| { 113 | if *hex_values { 114 | hex::decode(v).expect("Decoding failed") 115 | } else { 116 | v.clone().into_bytes() 117 | } 118 | }) 119 | .collect(), 120 | } 121 | } 122 | 123 | /// Create a trie from the key value yaml file and compute its hash and print it out. 124 | /// 125 | /// # Arguments 126 | /// 127 | /// * `Argmatches` - the resulting command line argument matches from clap processor related to state-trie command 128 | /// 129 | fn compute_state_root(&self) { 130 | let trie_vec: Vec<_> = self.keys.iter().zip(self.values.iter()).collect(); 131 | let state_trie_root = 132 | trie_root_no_extension::(trie_vec, None); 133 | println!("state root: {:x}", &state_trie_root); 134 | } 135 | 136 | /// Perform a sequentials insert and delete test: it insert the key value pairs from the yaml file 137 | /// One by one and compute the hash at each stages then it takes 138 | /// random steps in the key list equal to the first byte of the last hash it has computed and delete 139 | /// the key it lands on and print the hash of the the new trie. It continue this process till all 140 | /// keys are deleted. 141 | fn insert_and_delete_test(&mut self) { 142 | let mut memdb = MemoryDB::<_, HashKey<_>, _>::default(); 143 | let mut root = Default::default(); 144 | 145 | //let mut memtrie = RefTrieDBMutNoExt::new(&mut memdb, &mut root); 146 | pub type RefPolkadotTrieDBMutNoExt<'a> = 147 | trie_db::TrieDBMut<'a, GenericNoExtensionLayout>; 148 | let mut memtrie = RefPolkadotTrieDBMutNoExt::new(&mut memdb, &mut root); 149 | 150 | for i in 0..self.keys.len() { 151 | let key: &[u8] = &self.keys[i]; 152 | let val: &[u8] = &self.values[i]; 153 | memtrie.insert(key, val).unwrap(); 154 | memtrie.commit(); 155 | println!("state root: {:x}", memtrie.root()); 156 | } 157 | 158 | //now we randomly drop nodes 159 | while self.keys.len() > 0 { 160 | let key_index_to_drop = memtrie.root()[0] as usize % self.keys.len(); 161 | let key_to_drop = &self.keys[key_index_to_drop]; 162 | memtrie.remove(key_to_drop).unwrap(); 163 | memtrie.commit(); 164 | println!("state root: {:x}", memtrie.root()); 165 | self.keys.remove(key_index_to_drop); 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /fixtures/genesis-default/include.jl: -------------------------------------------------------------------------------- 1 | using .HostFixture 2 | using Test 3 | 4 | 5 | tester = HostFixture.Tester("Tester Genesis", "tester", "default") 6 | 7 | HostFixture.execute(tester, 10) do (root, result) 8 | # Extract all hashes returned from log 9 | hashes = map(m -> m[1], eachmatch(r"##([^#\n]+)##", result)) 10 | 11 | # Check state root hash 12 | @test root == hashes[1] 13 | 14 | 15 | # Extract all calls made from log 16 | calls = map(m -> m[1], eachmatch(r"@@([^@\n]+)@@", result)) 17 | 18 | # Check that grandpa config is requested 19 | @test "grandpa_authorities()" in calls 20 | 21 | # Check that babe configuration is requested 22 | @test "configuration()" in calls 23 | end 24 | -------------------------------------------------------------------------------- /fixtures/genesis-legacy/include.jl: -------------------------------------------------------------------------------- 1 | using .HostFixture 2 | using Test 3 | 4 | 5 | tester = HostFixture.Tester("Legacy Genesis", "tester", "legacy") 6 | 7 | HostFixture.execute(tester, 10) do (root, result) 8 | # Extract all hashes returned from log 9 | hashes = map(m -> m[1], eachmatch(r"##([^#\n]+)##", result)) 10 | 11 | # Check state root hash 12 | @test root == hashes[1] 13 | 14 | 15 | # Extract all calls made from log 16 | calls = map(m -> m[1], eachmatch(r"@@([^@\n]+)@@", result)) 17 | 18 | # Check that grandpa config is requested 19 | @test "grandpa_authorities()" in calls 20 | 21 | # Check that babe configuration is requested 22 | @test "configuration()" in calls 23 | end 24 | -------------------------------------------------------------------------------- /fixtures/host-api/HostApiFunctions.jl: -------------------------------------------------------------------------------- 1 | # Module which contains the names of the functions that need to be tested. 2 | # Thoses names get passed on to the CLI as`--function `. 3 | # The functions are grouped into arrays based on the expected (same) input data. 4 | module HostApiFunctions 5 | const none = [ 6 | "test_storage_init" 7 | ] 8 | 9 | const value = [ 10 | "ext_hashing_keccak_256_version_1", 11 | "ext_hashing_sha2_256_version_1", 12 | "ext_hashing_blake2_128_version_1", 13 | "ext_hashing_blake2_256_version_1", 14 | "ext_hashing_twox_256_version_1", 15 | "ext_hashing_twox_128_version_1", 16 | "ext_hashing_twox_64_version_1", 17 | "ext_allocator_malloc_version_1", 18 | "ext_allocator_free_version_1" 19 | ] 20 | 21 | const key_value = [ 22 | "ext_storage_set_version_1", 23 | "ext_storage_get_version_1", 24 | "ext_storage_clear_version_1", 25 | "ext_storage_exists_version_1" 26 | ] 27 | 28 | const child_key_value = [ 29 | "ext_default_child_storage_set_version_1", 30 | "ext_default_child_storage_get_version_1", 31 | "ext_default_child_storage_clear_version_1", 32 | "ext_default_child_storage_exists_version_1" 33 | ] 34 | 35 | const child_prefix_key_value_key_value = [ 36 | "ext_default_child_storage_clear_prefix_version_1" 37 | ] 38 | 39 | const child_key_value_key_value = [ 40 | "ext_default_child_storage_storage_kill_version_1", 41 | "ext_default_child_storage_root_version_1", 42 | "ext_default_child_storage_next_key_version_1" 43 | ] 44 | 45 | const child_key_value_offset_buffer_size = [ 46 | "ext_default_child_storage_read_version_1" 47 | ] 48 | 49 | const key_value_offset_buffer_size = [ 50 | "ext_storage_read_version_1" 51 | ] 52 | 53 | const prefix_key_value_key_value = [ 54 | "ext_storage_clear_prefix_version_1" 55 | ] 56 | 57 | const key_value_key_value = [ 58 | "ext_storage_append_version_1", 59 | "ext_storage_root_version_1", 60 | "ext_storage_next_key_version_1" 61 | ] 62 | 63 | const seed = [ 64 | "ext_crypto_ed25519_generate_version_1", 65 | "ext_crypto_sr25519_generate_version_1" 66 | ] 67 | 68 | # TODO: Expand seed data 69 | const seed_seed = [ 70 | "ext_crypto_ed25519_public_keys_version_1", 71 | "ext_crypto_sr25519_public_keys_version_1" 72 | ] 73 | 74 | # TODO: Expand seed data 75 | const seed_msg = [ 76 | "ext_crypto_ed25519_sign_version_1", 77 | "ext_crypto_ed25519_verify_version_1", 78 | "ext_crypto_sr25519_sign_version_1", 79 | "ext_crypto_sr25519_verify_version_1" 80 | ] 81 | 82 | const key_value_key_value_key_value = [ 83 | "ext_trie_blake2_256_root_version_1" 84 | ] 85 | 86 | const value_value_value = [ 87 | "ext_trie_blake2_256_ordered_root_version_1" 88 | ] 89 | 90 | const kind_key_value = [ 91 | "ext_offchain_local_storage_set_version_1", 92 | "ext_offchain_local_storage_get_version_1", 93 | "ext_offchain_local_storage_clear_version_1" 94 | ] 95 | 96 | const kind_key_value_value = [ 97 | "ext_offchain_local_storage_compare_and_set_version_1" 98 | ] 99 | end 100 | -------------------------------------------------------------------------------- /fixtures/host-api/include.jl: -------------------------------------------------------------------------------- 1 | include("./HostApiFunctions.jl") 2 | include("./HostApiInputs.jl") 3 | include("./HostApiOutputs.jl") 4 | 5 | using .StringHelpers 6 | using .AdapterFixture 7 | 8 | tests = AdapterFixture.Builder("Host API", `host-api`) 9 | 10 | HOSTAPI_FIXTURE_DATASETS = [ 11 | [ 12 | HostApiFunctions.none, 13 | nothing, 14 | HostApiOutputs.none, 15 | ],[ 16 | HostApiFunctions.value, 17 | [ 18 | HostApiInputs.value_1, 19 | ], 20 | HostApiOutputs.value .* "\n", 21 | ],[ 22 | HostApiFunctions.child_key_value, 23 | [ 24 | HostApiInputs.child_child, 25 | HostApiInputs.key_value_1, 26 | ], 27 | HostApiOutputs.child_key_value, 28 | ],[ 29 | HostApiFunctions.child_key_value_offset_buffer_size, 30 | [ 31 | HostApiInputs.child_child, 32 | HostApiInputs.key_value_1, 33 | HostApiInputs.offset, 34 | HostApiInputs.buffer_size, 35 | ], 36 | HostApiOutputs.key_value_offset_buffer_size .* "\n", 37 | ],[ 38 | HostApiFunctions.child_prefix_key_value_key_value, 39 | [ 40 | HostApiInputs.child_child, 41 | HostApiInputs.prefix_key_value_key_value, 42 | ], 43 | HostApiOutputs.child_prefix_key_value_key_value, 44 | ],[ 45 | HostApiFunctions.child_key_value_key_value, 46 | [ 47 | HostApiInputs.child_child, 48 | HostApiInputs.key_value_1, 49 | HostApiInputs.key_value_2, 50 | ], 51 | HostApiOutputs.child_key_value_key_value, 52 | ],[ 53 | HostApiFunctions.key_value, 54 | [ 55 | HostApiInputs.key_value_1, 56 | ], 57 | HostApiOutputs.key_value, 58 | ],[ 59 | HostApiFunctions.key_value_offset_buffer_size, 60 | [ 61 | HostApiInputs.key_value_1, 62 | HostApiInputs.offset, 63 | HostApiInputs.buffer_size, 64 | ], 65 | HostApiOutputs.key_value_offset_buffer_size .* "\n", 66 | ],[ 67 | HostApiFunctions.prefix_key_value_key_value, 68 | [ 69 | HostApiInputs.prefix_key_value_key_value, 70 | ], 71 | nothing, 72 | ],[ 73 | HostApiFunctions.key_value_key_value, 74 | [ 75 | HostApiInputs.key_value_1, 76 | HostApiInputs.key_value_2, 77 | ], 78 | HostApiOutputs.key_value_key_value .* "\n", 79 | ],[ 80 | HostApiFunctions.seed, 81 | [ 82 | HostApiInputs.seed_1, 83 | ], 84 | HostApiOutputs.seed .* "\n", 85 | ],[ 86 | HostApiFunctions.seed_seed, 87 | [ 88 | HostApiInputs.seed_1, 89 | HostApiInputs.seed_2, 90 | ], 91 | nothing, 92 | ],[ 93 | HostApiFunctions.seed_msg, 94 | [ 95 | HostApiInputs.seed_1, 96 | HostApiInputs.value_1[1:6], 97 | ], 98 | nothing, 99 | ],[ 100 | HostApiFunctions.key_value_key_value_key_value, 101 | [ 102 | HostApiInputs.key_value_1, 103 | HostApiInputs.key_value_2, 104 | HostApiInputs.key_value_3, 105 | ], 106 | HostApiOutputs.key_value_key_value_key_value .* "\n", 107 | ],[ 108 | HostApiFunctions.value_value_value, 109 | [ 110 | HostApiInputs.value_1, 111 | HostApiInputs.value_2, 112 | HostApiInputs.value_3, 113 | ], 114 | HostApiOutputs.value_value_value .* "\n", 115 | # ],[ 116 | # HostApiFunctions.kind_key_value, 117 | # [ 118 | # HostApiInputs.kind, 119 | # HostApiInputs.key_value_1, 120 | # ], 121 | # HostApiOutputs.kind_key_value, 122 | # ],[ 123 | # HostApiFunctions.kind_key_value_value, 124 | # [ 125 | # HostApiInputs.kind, 126 | # HostApiInputs.key_value_1, 127 | # HostApiInputs.value_1, 128 | # ], 129 | # HostApiOutputs.kind_key_value_value .* "\n", 130 | ] 131 | ] 132 | 133 | for (func, input, output) in HOSTAPI_FIXTURE_DATASETS 134 | sub!(tests) do t 135 | arg!(t, `--function`) 136 | foreach!(t, func) 137 | 138 | if input != nothing 139 | arg!(t, `--input`) 140 | foreach!(t, commajoin(flatzip(input...))) 141 | end 142 | 143 | commit!(t, output) 144 | end 145 | end 146 | 147 | AdapterFixture.execute(tests) 148 | -------------------------------------------------------------------------------- /fixtures/scale-codec/include.jl: -------------------------------------------------------------------------------- 1 | using .AdapterFixture 2 | 3 | 4 | const TEST_DATA = [ 5 | "1", 6 | "22", 7 | "333", 8 | "1234", 9 | "abcdefghijklmnopqrstuvwxyz", 10 | """A towel, it says, is about the most massively useful thing an 11 | interstellar hitch hiker can have. Partly it has great practical 12 | value - you can wrap it around you for warmth as you bound across 13 | the cold moons of Jaglan Beta; you can lie on it on the brilliant 14 | marble-sanded beaches of Santraginus V, inhaling the heady sea 15 | vapours; you can sleep under it beneath the stars which shine so 16 | redly on the desert world of Kakrafoon; use it to sail a mini 17 | raft down the slow heavy river Moth; wet it for use in hand-to- 18 | hand-combat; wrap it round your head to ward off noxious fumes or 19 | to avoid the gaze of the Ravenous Bugblatter Beast of Traal (a 20 | mindboggingly stupid animal, it assumes that if you can't see it, 21 | it can't see you - daft as a bush, but very ravenous); you can 22 | wave your towel in emergencies as a distress signal, and of 23 | course dry yourself off with it if it still seems to be clean 24 | enough.""" 25 | ] 26 | 27 | 28 | tests = AdapterFixture.Builder("Scale Codec", `scale-codec`) 29 | 30 | sub!(tests) do t 31 | arg!(t, `encode --input`) 32 | foreach!(t, TEST_DATA) 33 | commit!(t) 34 | end 35 | 36 | prepare!(tests) 37 | 38 | AdapterFixture.execute(tests) 39 | -------------------------------------------------------------------------------- /fixtures/state-trie/1c1.yaml: -------------------------------------------------------------------------------- 1 | keys: 2 | - 1 3 | values: 4 | - 1 5 | -------------------------------------------------------------------------------- /fixtures/state-trie/hex_1c1.yaml: -------------------------------------------------------------------------------- 1 | keys: 2 | - 01 3 | values: 4 | - 01 5 | -------------------------------------------------------------------------------- /fixtures/state-trie/hex_limit.yaml: -------------------------------------------------------------------------------- 1 | keys: 2 | - 00 3 | - 01 4 | - 3e 5 | - 3f00 6 | - 3f01 7 | - 3ffe 8 | - 3fff00 9 | - 3fff01 10 | - 3ffffe 11 | - 3fffff00 12 | - 3fffff01 13 | values: 14 | - Yahlae1echei3aG8aoNeesh3ungar1Ph 15 | - eej7Eeraja9ChohsCheeZae1gaeW4eilahngei7N 16 | - Wae4aengofoo9ohJizoo5ohCai9ahZapleeR8hazju2aiVee 17 | - Ung3aiP2aiv5Ediexaej0Ailaepe8oGaFee3ud3Reiquee8EIn0Ob5ph 18 | - Le9oo2eaEaph7eiteeVefiz6ees7aJaeoog5UseeSi8ahngushi0EngoDeiK5iag 19 | - Jah4Phaeoasei2TeOht7jeepieNei3igOef3MeedooXa5oorieT9zeigwie1ri3MOC7ceiweIxohyiw0faiK6phi 20 | - Eew4shohEeri0buoAechu8ohieth3TaeIew2oqueip5ail3Kbei6uPhiAebo6EikPaecha9uicaCipu5Za7Oovah 21 | - Iesh6xahUji8bi2sQuaive0eae9Dah2iyuVo9rohQuoh7eehmoo0luMeie7itohHquaiM1Azdoo5bieKcaoCh8niiem3uGah 22 | - Thee4vohrahTai3ire0YiK5Igohg0iaRookue4OhKoo9oolalei8SoawEingech0Xi8fogheooC2ek2aqueiG8Olov8wie6XiuPeeb8Eagh1loNg 23 | - vauWe5exAhse4EerEmeo6EpiiRaid6ahQuiKah6xAishocu1De3aexeiFah1Ahp0echieM1dAiPhae1uahsh1OhjOht4OoN4Ohdi7ineUequ5eezig1keiGi 24 | - lahQu5ielah4feiWoYii1ri7uo0eiZieZahu0ohxLaiG7eshooMuSh6hThou9jahIa8oodooaeMaix8iiel5Ao2hxoo4Eir1Oop7phiToo2IerahEita0chogoh7rieC 25 | -------------------------------------------------------------------------------- /fixtures/state-trie/hex_long.yaml: -------------------------------------------------------------------------------- 1 | keys: 2 | - bd3d57ecfe0c34f6b3ec5df8a8fa01ccdca0a35e6a0e9c3a7c62d9475749e3ce13db662770041ecd9045751c0362f2de3279a94841e0abc93af3ceec9a637392 3 | - 0e54fbe39734be1d9e10a2183a114a7de6bfabbb03152edfb1dd6ce54d005e9c2c9a9c066cff3cecc4f87ea1b8359f4742e0b90195083694218e05bbba442419 4 | - e0fea05ff2d3dd3a4b5efbe81dda860cf813e9002a039dd8f5a66cbe6146f1bf7864909d622654bc0278c635883e570c5233ddd24493ef2f7499352d508ce9c0 5 | - 27150151da7bd8f98c94cb100d4a9c525c98aac8264c0319632f2c589ce5f3e041259d13ebf4c90deec9c4405417d1e72e08270e8ea06f4f7522c64f3522b819 6 | - 3e086562db996b20fa2a8dd95c4e9f4bb63828777d6bd7a2e2d149d8d057c0a8dc55927461dcffdf4a93fed8323bb2645ce52337634b9a7f03b80692b3ecca88 7 | - b36a23c1bbb13ff67f533110e0fb217b74d786aeb53b95b578abbfdf50e2e1b513529b654b5e2eede1c8928693c827a18ada0490ce857152f70c96f33d7b6929 8 | - c8fa232eef0b437de629c746a08d124ddffddeabbe191c5375d93affa1d9be7c08132f799a5de065860bbf73e4fa425b77c1aa4a6f2f9f168aca0c63b3f876f7 9 | - c8fae94f2fd159403935ce90f8132b7e933efe0ad12f6d4115bf01d3f562ed0e6386003b37e2797c110a1917a5568c3ceec2cd720baeaf333a5455d8bc26894f 10 | - 43ccc1530a6a5ba58cca589caeba9f4fe18dc82d250e93957f923978b0d519b87f1694d33e7d6d7b9bf1a2a93fbfc3f957e633c90e6ce9f8b94b98766aeb15ac 11 | - 394b66a5f3622c6dd76b9768da7153bfac7645ebbfd5e794063740cf884e8a06f00f82bba8a78a3ed7ae3ecb066196cd75ba95018aa834bb74e98080e54a1886 12 | - c53651c0a486d12d66f388ef874e91d45c809f7194d8f1c68341ae557f8acdf8ea133d511ab212b266bf691a5609425335f15da2d548d8e7d421dd29c5840fb0 13 | - 952299c29b636fbdec38d27490359881ec29527501b6d6b83fa56085e959c5d38530803cfbdce1467f76d450967b6b271f783f4ef636b0d09d19dfd514053421 14 | - 623b24767a55c2441629dd7a96efb9a998fa5cec6ac80afdf9fc35b393050da5aa0e3cf184f07d1d29f5b24c296460e98d72ad2119a0930cd9da3e06c57c4fd4 15 | - 6dfd3edc577ee49958938ac6b0f3b0cd233ea4b707cbcfaf1f2c416070dad04c468c7fb76aaee100764eabcd8f035b1fcdd4fd0393aa247cfd121cb29b6b3f71 16 | - c5c6035c34c77d494264c825b0b9b059a33af4e8f7c0992852680ed52eeffc61aec9319c6a038a567f1cb761d3e614dcfac50b2ab0874ed8c240dbe8644856fd 17 | - f729a5ead9b22c0f0bb9060579c0524e7b251e6708dd8e15fc830e1fb823df45b8179ad233ab1da2f790a93a804ead554669a179e82dc916cd4571c1a2079971 18 | values: 19 | - yE9lmCZ0z4C6UKl3VUj9HBE1mYv9QkPQqT570zr49HOeSTsOzTytdqJHzzPFG79KpUsANML2hceMMfKpXFPHDwSkOxJIvMkmqDyo7Rm3zpqpm7kyiVmsrcSSO8Lula41 20 | - BmJv7BnBof8osSQp7VBp1xDx5ZBGzurGKn0a8M6qRh1iiqBYXIMdTnP5wH5e7cnEWqC0uOQViB7iZVM9s9cDMWcyus54czuysQ1eQl4i3Fps9LhLKDnxzvFEwtt5vJvg 21 | - IYlB0hgm4luVoITjgtP2jUZkHZf7pw9YO9dFvbOHHUr8PkU9YV1mIkRxDvj90e7sRBdHYIr25PhrxZltKL61Lv3asgGzC1Yh7x5xSYKwjvBi0GavPEMgN6022PaCuRNU 22 | - OGiGQ6bYpRNJa3gwReD4bO5JHdmKgTO9EiE6zFPaxD5BgW3Q2rX0JZwDer6CMfxhtdPsgDYv7hpOcaEgUQO1spMtF20xf71X7F072lAF4U35hl6W5NYztFpSu9AGW6iv 23 | - b5RfGBbbMOWzw28EnwVkjT3FpnYwPl44nxBFn7Gccy4DRiS2TwVItbVOP4SFwEYFhKAUlBSBwjZEyroS8ANH1RxNpmKyZjcaidyOzXbotxqG1vNA4mcmuSlAUZ7kxl8C 24 | - RHevA5nBBLQBeNz2LgtdHHYDz16Y4HUnHjnkmdYqeSpEL30RzHQyfFq8EhioKyx4Z4qDiKCE1YyczdLInbtyU2GJmusDV9G14lxNzixIJWXm1ZvHNvUEJF3iiLKnFCoc 25 | - cvcC1jGGEmczwSX9VRDCiWm3mAejWM7Caanl1nEU5DQzMoPA2zj1BcAudVEkEjwfYZZm5mabryCrz68OiKV5iDM49IhVgreBzif1MEJmlBc84hJojP9oRzn1PHWy2lnc 26 | - mjfKDQBx60izV4JmNWOnEYb2poHRpb0Xaal8o81XBVUzwFM1LhJRN9zRPUHJFTlnvPZEp2us4a2nk7ZXFHDXWEgZYtaX4O9CrvvFSsd03doZO2sHFMWO85GRrLvmg2ZX 27 | - IyFCXKDamoEuDB59bRgRA0Kel91mxe3qrAxfAd0iPi8FRYH1nUJ9mvkZuTigSMcU4YqMpP8zCc5C02VB19sUQIh0zyg6rxctWVlOgoQNeqUr2rpnD5MfvWC0VvEbOuvI 28 | - AAM0hWY4TtdlYXiw9FAuVKRL64IXoVfnTVOeQAABovBfopYHfY5S8OLYfmy3QDd1sNKgi2WqBB8OhefznT39CPkZDvh7s37Lng19cenEjKTOrDxVZforh5tEbS0ejxT3 29 | - rfIqBp2TNRC1VSOvVufIWejUrFweM89WPcm67dzMUO6QA40juliyYcplk0xhvHMbKrJuRl07Hv7waRZbruT019BfvesSCh7UssOHRbssTWXAvlnUEJUL2tbEsgbzxfQk 30 | - zRFijByUjvCXFGvTUvaeYeeEqzl0JdWWNQiIvuvb8JoiYagGToSxLQK3om8FHXvEY9YFicrNJPIwDCejNLjc1nNmVFRQmrxbhLqZ7lQqMhswtEffcGewtAGyA7wHwW3p 31 | - ij2MzMX8TNEd0BoRmc9DW002zG03tOqnxCbSYBaXPkDjVHlhVMxLgzyGJTNu1BnroBOzFk2oNKTcohPdQmq8czWPrnw43uyJFgrANQyR4s94afXhS0zPHztacQVnxCw5 32 | - 0b2fURCd47Ap6qq6wVdRPhUCiCSGgKsRLbvPawA7SAnnrLZLZLrXziRSUYA2GE4MpJpuAXawEXCycAT6UMX9rxhIs2GZfDPhwIuGvn2XLmr2YSkZGiSmfmU23LH8oeBh 33 | - VyHilL2YrQm8iXsXS36CA3zFtua7xGhlLEIrLZ2Tzr3yFseVTASRrro4pb2nh4knGm9ccaj817sJMmhYTkGEqLYxFK8Cg2f3k9EOy127pbrgORgQXDZGnQofUwbUhoA0 34 | - VuEIroaAF6UttEfgijN4aI0eh26NSjBQi1AIedKOHiHNFFXlazxBvRDXAnAfdBnbaYxCixXdFmVradlQdXudWSuVsAMYnzoyorkYI0B1eXihk8Escvjtza78jPxzOzzJ 35 | -------------------------------------------------------------------------------- /fixtures/state-trie/include.jl: -------------------------------------------------------------------------------- 1 | using .AdapterFixture 2 | 3 | 4 | const TEST_DIR = "$(@__DIR__)/" 5 | 6 | const TEST_FILES = TEST_DIR .* [ 7 | "1c1.yaml", 8 | "scv.yaml", 9 | "random_state_80.yaml", 10 | "pk_branch.yaml", 11 | "pk_branch2.yaml", 12 | "hex_limit.yaml", 13 | "hex_long.yaml", 14 | ] 15 | 16 | const TEST_FILES_HEX = TEST_DIR .* [ 17 | "hex_1c1.yaml", 18 | "hex_limit.yaml", 19 | "hex_long.yaml", 20 | "10000_node.yaml", 21 | ] 22 | 23 | 24 | tests = AdapterFixture.Builder("State Trie", `state-trie`) 25 | 26 | sub!(tests) do t 27 | arg!(t, `trie-root --state-file`) 28 | foreach!(t, TEST_FILES) 29 | commit!(t) 30 | end 31 | 32 | sub!(tests) do t 33 | arg!(t, `insert-and-delete --state-file`) 34 | foreach!(t, TEST_FILES) 35 | commit!(t) 36 | end 37 | 38 | sub!(tests) do t 39 | arg!(t, `trie-root --keys-in-hex --state-file`) 40 | foreach!(t, TEST_FILES_HEX) 41 | commit!(t) 42 | end 43 | 44 | prepare!(tests) 45 | 46 | AdapterFixture.execute(tests) 47 | -------------------------------------------------------------------------------- /fixtures/state-trie/pk_branch.yaml: -------------------------------------------------------------------------------- 1 | keys: 2 | - 1357 3 | - 13579 4 | values: 5 | - 1 6 | - 234567890qwertyuiopasdfghjklzxcvbnm 7 | -------------------------------------------------------------------------------- /fixtures/state-trie/pk_branch2.yaml: -------------------------------------------------------------------------------- 1 | keys: 2 | - 12345 3 | - abcd 4 | - zyxw 5 | - azyx 6 | - mnopqrst 7 | - ab123 8 | - ii1234 9 | - Oif4daiN 10 | - Ye 11 | - JJ 12 | - Qui 13 | - Vo1 14 | values: 15 | - 1 16 | - 2 17 | - 3 18 | - 1234567890asdfghjklmnbvcxzqertyuiop 19 | - 4 20 | - 5 21 | - 6 22 | - 7 23 | - 8 24 | - 9 25 | - Yei1Iesh 26 | - Vo1Xavah 27 | -------------------------------------------------------------------------------- /fixtures/state-trie/random_state_80.yaml: -------------------------------------------------------------------------------- 1 | keys: 2 | - eiChooB8 3 | - Ahgh0aen 4 | - Moo7ohya 5 | - ia0Meiye 6 | - Iur3aoSh 7 | - Iu4Lohsi 8 | - Foc6aip7 9 | - yie6iThi 10 | - Zah4yok0 11 | - aimu8hoL 12 | - ieh4Peis 13 | - fiS2uash 14 | - Quufai5a 15 | - queC4mei 16 | - if4aix7W 17 | - daez7AhV 18 | - oofaic3R 19 | - liug2aiN 20 | - aiZah5di 21 | - aiziC5ei 22 | - Aegh9eiM 23 | - gohxi3Ke 24 | - oL3aewuB 25 | - AB6ahrae 26 | - ekichu5 27 | - Op1uTa2o 28 | - ohli4Am7 29 | - aeg6Phae 30 | - Equiegh4 31 | - Oogu8AiR 32 | - ieGh8eeS 33 | - thieM0ie 34 | - n7aeth8 35 | - eilohNg6 36 | - IetiePa8 37 | - cooW5eey 38 | - AeGhuk4r 39 | - zoogiJu4 40 | - jei7Dohy 41 | - rahd1eiJ 42 | - u9aizee 43 | - aeb4BohK 44 | - eibo6uoD 45 | - eichee2X 46 | - Kaedaes4 47 | - ze8thohR 48 | - OhNe5zei 49 | - ohY8quuG 50 | - z8beiz3 51 | - no5Jahqu 52 | - Tie5look 53 | - Foo8thui 54 | - uyeeJ0ai 55 | - aub5ohKa 56 | - iel9bahB 57 | - uloo4Vah 58 | - iwooz8E 59 | - phoCie6e 60 | - AiV8oagh 61 | - aDie5Lee 62 | - Tie9ahce 63 | - aeph5Koo 64 | - Ahraey7r 65 | - eare7Eix 66 | - a1zith1 67 | - jahYai7c 68 | - evu4Ohph 69 | - Ol6cohvu 70 | - aY5xao3b 71 | - eree2eiC 72 | - ooNaeg9A 73 | - eit9aeJa 74 | - ae9ieLo 75 | - Teith6zu 76 | - Yei1Iesh 77 | - Vo1Xavah 78 | - QuiQuie6 79 | - aTei3kai 80 | - Bohpoh8u 81 | - Oif4daiN 82 | values: 83 | - a8aqu5a 84 | - Od8Ralie 85 | - Dai7ieto 86 | - EmooR1ai 87 | - veeReek9 88 | - vohGho1W 89 | - ahL0ola9 90 | - Riugai3U 91 | - otho8ee 92 | - Choa3ooy 93 | - Kiad5eiP 94 | - cahY6zoh 95 | - yaeDo1so 96 | - Eu1ahquo 97 | - Ay0buth6 98 | - ieBaex3o 99 | - aiBee3o 100 | - eetie3Ea 101 | - ieyai1Ee 102 | - weinah1O 103 | - ieRa7uwi 104 | - kiu3Dah7 105 | - ui7Aequi 106 | - Icie0oom 107 | - hiJei3r 108 | - ohku2Uaz 109 | - bahr0Ohl 110 | - Ia4iphai 111 | - oufah9La 112 | - ReiMei7k 113 | - Pha8Eequ 114 | - joo7Geeh 115 | - ohSh6la 116 | - airek9Ch 117 | - Fae7zeeg 118 | - eequ8Ene 119 | - PaeXie6e 120 | - phoxo3Oo 121 | - Dahwach4 122 | - jee3Iph4 123 | - eGie2Ei 124 | - vaaXei3k 125 | - ahbo9ieN 126 | - ooR1shei 127 | - Xide4gei 128 | - Aethu4ii 129 | - jook1Cho 130 | - chai3Fik 131 | - hlooc0U 132 | - thee3Och 133 | - ELaQu8ph 134 | - Gah0Chod 135 | - yaiz7Kud 136 | - tau3zoaF 137 | - auCah5Oo 138 | - sae4Ahf3 139 | - hee3Ieh 140 | - ta2Ashee 141 | - ceeQuei8 142 | - jeef8aNg 143 | - Ohquiay3 144 | - zo7Iekei 145 | - ii2dohGh 146 | - ohghe1Ko 147 | - Ng3aiTh 148 | - ha7xu6oJ 149 | - Ra3chail 150 | - aen7looY 151 | - Eepeez1i 152 | - neePo8ai 153 | - Goh1tail 154 | - yoh7Ohth 155 | - hnied1i 156 | - Pheewa6I 157 | - ais2aiWi 158 | - yaighe6G 159 | - che5Hohw 160 | - aiPiey2w 161 | - iyeequ3C 162 | - woo9eiCh 163 | -------------------------------------------------------------------------------- /fixtures/state-trie/scv.yaml: -------------------------------------------------------------------------------- 1 | keys: 2 | - s 3 | values: 4 | - v 5 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "fenix": { 4 | "inputs": { 5 | "nixpkgs": [ 6 | "nixpkgs" 7 | ], 8 | "rust-analyzer-src": "rust-analyzer-src" 9 | }, 10 | "locked": { 11 | "lastModified": 1675319011, 12 | "narHash": "sha256-03XIeP5ohqMs+AXhKirbZXMjEfmWmasrcnQIZW1hPbM=", 13 | "owner": "nix-community", 14 | "repo": "fenix", 15 | "rev": "5039231f7fbf180ea25b5d7eac907d5058382c1c", 16 | "type": "github" 17 | }, 18 | "original": { 19 | "owner": "nix-community", 20 | "repo": "fenix", 21 | "type": "github" 22 | } 23 | }, 24 | "gossamer-submodule": { 25 | "flake": false, 26 | "locked": { 27 | "lastModified": 1674836942, 28 | "narHash": "sha256-DxT3DMwMChiNFSMBpCuKc7eA0Vri95zdnBKuO2nDZA8=", 29 | "ref": "c9587208c74bad29b40163dbbbfc0a986d930ce2", 30 | "rev": "c9587208c74bad29b40163dbbbfc0a986d930ce2", 31 | "revCount": 1532, 32 | "type": "git", 33 | "url": "file:./hosts/gossamer" 34 | }, 35 | "original": { 36 | "type": "git", 37 | "url": "file:./hosts/gossamer" 38 | } 39 | }, 40 | "kagome-submodule": { 41 | "flake": false, 42 | "locked": { 43 | "lastModified": 1674829712, 44 | "narHash": "sha256-XobLU6bszE5h0IKTReI/djCjB8BuGCjXJwE1jT0JUNM=", 45 | "ref": "aa34f26ac559ac2c1afb8a4677e11ebf081e1d3a", 46 | "rev": "aa34f26ac559ac2c1afb8a4677e11ebf081e1d3a", 47 | "revCount": 863, 48 | "type": "git", 49 | "url": "file:./hosts/kagome" 50 | }, 51 | "original": { 52 | "type": "git", 53 | "url": "file:./hosts/kagome" 54 | } 55 | }, 56 | "naersk": { 57 | "inputs": { 58 | "nixpkgs": [ 59 | "nixpkgs" 60 | ] 61 | }, 62 | "locked": { 63 | "lastModified": 1662220400, 64 | "narHash": "sha256-9o2OGQqu4xyLZP9K6kNe1pTHnyPz0Wr3raGYnr9AIgY=", 65 | "owner": "nix-community", 66 | "repo": "naersk", 67 | "rev": "6944160c19cb591eb85bbf9b2f2768a935623ed3", 68 | "type": "github" 69 | }, 70 | "original": { 71 | "owner": "nix-community", 72 | "repo": "naersk", 73 | "type": "github" 74 | } 75 | }, 76 | "nixpkgs": { 77 | "locked": { 78 | "lastModified": 1660926553, 79 | "narHash": "sha256-19Ib1b7Ny+yGhnxwnH1KhhB2hvALuNuqevA6XzqkQmo=", 80 | "path": "/nix/store/5mdm97ryfgnsh02h7jiragdmcgh6vbvp-source", 81 | "rev": "00e376e3f3c22d991052dfeaf154c42b09deeb29", 82 | "type": "path" 83 | }, 84 | "original": { 85 | "id": "nixpkgs", 86 | "type": "indirect" 87 | } 88 | }, 89 | "root": { 90 | "inputs": { 91 | "fenix": "fenix", 92 | "gossamer-submodule": "gossamer-submodule", 93 | "kagome-submodule": "kagome-submodule", 94 | "naersk": "naersk", 95 | "nixpkgs": "nixpkgs", 96 | "substrate-submodule": "substrate-submodule", 97 | "utils": "utils" 98 | } 99 | }, 100 | "rust-analyzer-src": { 101 | "flake": false, 102 | "locked": { 103 | "lastModified": 1675281619, 104 | "narHash": "sha256-cxZylukIcY5Ik29zXD+7e8krHVZ4XnTYJsjLkQRk3v8=", 105 | "owner": "rust-lang", 106 | "repo": "rust-analyzer", 107 | "rev": "ccd142c6163c992dfb482b85bbddbb7b3370c9c8", 108 | "type": "github" 109 | }, 110 | "original": { 111 | "owner": "rust-lang", 112 | "ref": "nightly", 113 | "repo": "rust-analyzer", 114 | "type": "github" 115 | } 116 | }, 117 | "substrate-submodule": { 118 | "flake": false, 119 | "locked": { 120 | "lastModified": 1675033036, 121 | "narHash": "sha256-/GBw0VBpFxTnl6NVnXC8UDWIgTNCvuTVObUWaCfpN0o=", 122 | "ref": "f0e1ed0bab6d5cb542b84fa0ad464609198dd255", 123 | "rev": "f0e1ed0bab6d5cb542b84fa0ad464609198dd255", 124 | "revCount": 3789, 125 | "type": "git", 126 | "url": "file:./hosts/substrate" 127 | }, 128 | "original": { 129 | "type": "git", 130 | "url": "file:./hosts/substrate" 131 | } 132 | }, 133 | "utils": { 134 | "locked": { 135 | "lastModified": 1667395993, 136 | "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", 137 | "owner": "numtide", 138 | "repo": "flake-utils", 139 | "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", 140 | "type": "github" 141 | }, 142 | "original": { 143 | "owner": "numtide", 144 | "repo": "flake-utils", 145 | "type": "github" 146 | } 147 | } 148 | }, 149 | "root": "root", 150 | "version": 7 151 | } 152 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "W3F Polkadot Protocol Testsuite"; 3 | 4 | inputs = { 5 | # Local git submodules (needs manual update) 6 | gossamer-submodule = { 7 | url = "git+file:./hosts/gossamer"; 8 | flake = false; 9 | }; 10 | kagome-submodule = { 11 | url = "git+file:./hosts/kagome"; 12 | flake = false; 13 | }; 14 | substrate-submodule = { 15 | url = "git+file:./hosts/substrate"; 16 | flake = false; 17 | }; 18 | 19 | # Nix utils libraries 20 | utils.url = "github:numtide/flake-utils"; 21 | 22 | # Rust toolchain parsing and build tools 23 | fenix = { 24 | url = "github:nix-community/fenix"; 25 | inputs.nixpkgs.follows = "nixpkgs"; 26 | }; 27 | 28 | naersk = { 29 | url = "github:nix-community/naersk"; 30 | inputs.nixpkgs.follows = "nixpkgs"; 31 | }; 32 | }; 33 | 34 | outputs = { self, utils, nixpkgs, fenix, naersk, ... } @ inputs: 35 | utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system: 36 | let 37 | # Provide commen shorthands 38 | pkgs = nixpkgs.legacyPackages.${system}; 39 | 40 | # Intialize rust toolchain based on toolchain file 41 | rustToolchain = fenix.packages.${system}.fromToolchainFile { 42 | file = ./rust-toolchain.toml; 43 | sha256 = "R6uGJG/aH25t3CEXyD28m4b7HRYvjtCqzRtfBqIFfi4="; 44 | }; 45 | 46 | naerskToolchain = naersk.lib.${system}.override { 47 | rustc = rustToolchain; 48 | cargo = rustToolchain; 49 | }; 50 | 51 | # Intialize package set 52 | submodules = { 53 | inherit (inputs) gossamer-submodule kagome-submodule substrate-submodule; 54 | }; 55 | 56 | packages = import ./.nix/packages.nix { 57 | inherit self pkgs submodules; 58 | naersk = naerskToolchain; 59 | }; 60 | 61 | in { 62 | devShells = { 63 | # Shell including all required dependecies 64 | default = pkgs.mkShell { 65 | inputsFrom = builtins.attrValues self.packages.${system}; 66 | buildInputs = [ pkgs.gnumake ]; 67 | }; 68 | 69 | # General shell for substrate-based development 70 | substrate = pkgs.callPackage ./.nix/substrate/env.nix { 71 | inherit rustToolchain; 72 | }; 73 | }; 74 | 75 | # All testsuite related binaries and testsuite itself 76 | packages = packages.hosts // packages.testsuite // { 77 | inherit rustToolchain; 78 | default = packages.polkadot-testsuite; 79 | }; 80 | } 81 | ) // { 82 | # We currently only check on x86_64-linux 83 | checks.x86_64-linux = self.packages.x86_64-linux; 84 | }; 85 | } 86 | -------------------------------------------------------------------------------- /helpers/AdapterFixture.jl: -------------------------------------------------------------------------------- 1 | module AdapterFixture 2 | 3 | export sub!, arg!, foreach!, commit!, reset!, clear!, prepare! 4 | 5 | 6 | using Test 7 | 8 | using ..StringHelpers 9 | using ..Config 10 | 11 | 12 | "Exit code to state outcome of adapter test, based on errno" 13 | @enum AdapterExitCode Success Failure NotSupported=95 14 | 15 | 16 | "Structure used behind the scene to collect test cases" 17 | mutable struct Builder 18 | "Name of the testsuite" 19 | name::String 20 | 21 | "Value to which to reset" 22 | default::Cmd 23 | 24 | "Command currently being constructed" 25 | current::CmdList 26 | 27 | "Collection of all commands to run" 28 | inputs::CmdList 29 | 30 | "Expected output generated with reference implementations" 31 | outputs::MaybeStringList 32 | 33 | "Constructor: Only allow to set name on construction" 34 | Builder(name, default=``) = new(name, default, [default], [], []) 35 | end 36 | 37 | 38 | "Basic iterator support" 39 | Base.iterate(b::Builder, i=1) = i > length(b.inputs) ? nothing : (b.inputs[i], i+1) 40 | Base.eltype(::Type{Builder}) = Int 41 | Base.length(b::Builder) = length(b.inputs) 42 | 43 | 44 | "Create subcontext and add inputs to main context after execution" 45 | function sub!(context!::Function, self::Builder) 46 | copy = deepcopy(self) 47 | 48 | clear!(copy) 49 | context!(copy) 50 | 51 | append!(self.inputs, copy.inputs) 52 | append!(self.outputs, copy.outputs) 53 | end 54 | 55 | "Add arguments to commands currently being build" 56 | function arg!(self::Builder, arg::CmdString) 57 | self.current = cmdcombine(self.current, arg) 58 | end 59 | 60 | "Add each argument to commands currently being build" 61 | function foreach!(self::Builder, args::CmdStringList) 62 | self.current = cmdcombine(self.current, args) 63 | end 64 | 65 | """ 66 | Commit commands currently being build to inputs list, expects `prepare!` 67 | to be run before execution to generate expected ouputs. 68 | """ 69 | function commit!(self::Builder) 70 | append!(self.inputs, self.current) 71 | end 72 | 73 | """ 74 | Commit commands currently being build to inputs list together with list 75 | of expected output. Use nothing entries to disable output checks. 76 | """ 77 | function commit!(self::Builder, outputs::MaybeStringList) 78 | if length(outputs) != length(self.current) 79 | error("Different count of Inputs and expected outputs.") 80 | end 81 | 82 | append!(self.outputs, outputs) 83 | append!(self.inputs, self.current) 84 | end 85 | 86 | """ 87 | Commit commands currently being build to inputs list together with a single 88 | expected output for all of them. Use nothing to disable output checks. 89 | """ 90 | function commit!(self::Builder, output::MaybeString) 91 | commit!(self, MaybeStringList(output, length(self.current))) 92 | end 93 | 94 | "Reset current command being build to default" 95 | function reset!(self::Builder) 96 | self.current = [self.default] 97 | end 98 | 99 | "Clear all commands committed so far" 100 | function clear!(self::Builder) 101 | self.inputs = StringList() 102 | self.outputs = StringList() 103 | end 104 | 105 | 106 | "Cache expected output by running reference implementation, substrate by default." 107 | function prepare!(self::Builder, implementation="substrate") 108 | self.outputs = [] 109 | for (i, args) in enumerate(self.inputs) 110 | try 111 | cmd = `$(implementation)-adapter $args` 112 | push!(self.outputs, read(cmd, String)) 113 | catch e 114 | error("Failed to cache reference output: $e") 115 | end 116 | end 117 | end 118 | 119 | "Run all commited test for specified adapter." 120 | function run(self::Builder, adapter::CmdString) 121 | if length(self.inputs) != length(self.outputs) 122 | error("Missing or outdated cached reference outputs") 123 | end 124 | 125 | for (input, output) in zip(self.inputs, self.outputs) 126 | 127 | # Execute adapter and collect output and exit code 128 | args = cmdjoin(input, Config.extra_args) 129 | cmd = cmdjoin(adapter, args) 130 | 131 | if Config.verbose 132 | println("┌ [COMMAND] ", cmd) 133 | end 134 | 135 | stream = Pipe() 136 | proc = Base.run(pipeline(ignorestatus(cmd), stdout=stream, stderr=stream)) 137 | close(stream.in) 138 | result = read(stream, String) 139 | 140 | # Check if adapter is missing adaption (special case) 141 | if proc.exitcode == Int(NotSupported) 142 | @warn "Missing adaption: $cmd" 143 | @test_skip AdapterExitCode(proc.exitcode) == NotSupported 144 | continue 145 | end 146 | 147 | # Check exit code and result 148 | if success(proc) 149 | if output != nothing 150 | # Default: Compare result against expected result 151 | @test result == output 152 | else 153 | # Empty outputs are used to disable comparison 154 | @test output == nothing 155 | end 156 | 157 | else 158 | @error "Adapter failed running $cmd:\n$result" 159 | @test success(proc) 160 | end 161 | 162 | if Config.verbose 163 | if success(proc) 164 | if output != nothing 165 | println("└ [OUTPUTS] ", result) 166 | else 167 | println("└ [IGNORED] ", result) 168 | end 169 | else 170 | println("└ [FAILED] (", proc.exitcode, ") ", result) 171 | end 172 | 173 | if isempty(result) 174 | println() 175 | end 176 | end 177 | end # for inputs 178 | end 179 | 180 | "Run fixture for each configured implementation" 181 | function execute(self::Builder) 182 | @testset "$(self.name)" begin 183 | for implementation in Config.implementations 184 | adapter = "$implementation-adapter" 185 | run(self, adapter) 186 | end # for implementations 187 | end # testset over execute 188 | end 189 | 190 | end # module 191 | -------------------------------------------------------------------------------- /helpers/HostFixture.jl: -------------------------------------------------------------------------------- 1 | module HostFixture 2 | 3 | using ..Config 4 | using Test 5 | 6 | "Represensts a fixture based on a tester runtime" 7 | struct Tester 8 | "Name of the testsuite" 9 | name::String 10 | 11 | "Name of the runtime to use" 12 | runtime::String 13 | 14 | "Name of the runtime variant" 15 | variant::String 16 | end 17 | 18 | 19 | "Load trie root hash from hash file" 20 | function load_hash(self::Tester) 21 | hash_file = "$(@__DIR__)/../runtimes/$(self.runtime)/genesis.$(self.variant).hash" 22 | 23 | # Make sure hash file is available 24 | if !isfile(hash_file) 25 | @error "Failed to locate hash file: $hash_file" 26 | end 27 | 28 | return open(hash_file) do f 29 | read(f, String) 30 | end 31 | end 32 | 33 | 34 | "Run host with tester genesis for certain time in seconds" 35 | function run_tester(self::Tester, host::String, duration::Number) 36 | # Locations of needed files and folders 37 | tempdir = mktempdir() * "/" 38 | 39 | # Determine correct genesis of runtime 40 | genesis = "$(@__DIR__)/../runtimes/$(self.runtime)/genesis.$(self.variant).json" 41 | 42 | # Make sure genesis is available 43 | if !isfile(genesis) 44 | @error "Failed to locate genesis: $genesis" 45 | end 46 | 47 | # gossamer: Provide basic config file 48 | config = "$(@__DIR__)/../runtimes/$(self.runtime)/gossamer.config.toml" 49 | 50 | # kagome: Provide populated keystore (TODO: Load chain id from genesis) 51 | keystore = "$(@__DIR__)/../runtimes/$(self.runtime)/keystore" 52 | mkpath(joinpath(tempdir, "spectest")) 53 | cp(keystore, joinpath(tempdir, "spectest", "keystore")) 54 | 55 | # By default the tempdir is used for local data 56 | datadir = tempdir 57 | 58 | if Config.docker 59 | # Provide genesis and other files to container 60 | cp(genesis, joinpath(tempdir, basename(genesis))) 61 | cp(config, joinpath(tempdir, basename(config))) 62 | 63 | # Use fixed dir inside container 64 | datadir = "/data" 65 | 66 | genesis = joinpath(datadir, basename(genesis)) 67 | config = joinpath(datadir, basename(config)) 68 | end 69 | 70 | # Prepare command and environment based on command 71 | exec = `` 72 | args = `` 73 | if host == "substrate" 74 | exec = `polkadot` 75 | args = `--alice --chain $genesis -d $datadir` 76 | ENV["RUST_LOG"] = "runtime=debug" 77 | elseif host == "kagome" 78 | exec = `kagome` 79 | args = `--chain $genesis -d $datadir --bootnodes /dns/localhost/tcp/30363/p2p/12D3KooWEgUjBV5FJAuBSoNMRYFRHjV7PjZwRQ7b43EKX9g7D6xV` 80 | elseif host == "gossamer" 81 | exec = `gossamer` 82 | args = `--key alice --genesis $genesis --config $config --basepath $datadir --log debug` 83 | else 84 | error("Unknown host: ", host) 85 | end 86 | 87 | # Prepare container and overwrite command with docker invocation 88 | if Config.docker 89 | image = Config.get_container(host) 90 | 91 | if isempty(image) 92 | @error "Host '$host' has no default docker image." 93 | end 94 | 95 | println("Caching/updating docker images of '$host':") 96 | run(`docker pull $image`) 97 | 98 | exec = `docker run -e RUST_LOG=runtime=debug -v $tempdir:$datadir --rm -i $image` 99 | end 100 | 101 | cmd = `$exec $args $(Config.extra_args)` 102 | 103 | if Config.verbose 104 | println("┌ [COMMAND] ", cmd) 105 | end 106 | 107 | # Run for specified time 108 | stream = Pipe() 109 | proc = run(pipeline(cmd, stdout = stream, stderr = stream), wait = false) 110 | sleep(duration) 111 | 112 | # Stop process if necessary 113 | crashed = !process_running(proc) 114 | if !crashed 115 | kill(proc) 116 | 117 | while (process_running(proc)) 118 | sleep(0.1) 119 | end 120 | end 121 | 122 | # Retrieve result 123 | close(stream.in) 124 | result = read(stream, String) 125 | 126 | # Check and warn about unexpected crashes 127 | if crashed 128 | @warn "Host '$host' aborted unexpectedly:\n$result" 129 | end 130 | 131 | @test !crashed 132 | 133 | if Config.verbose 134 | println("└ [OUTPUTS] ", result) 135 | end 136 | 137 | return result 138 | end 139 | 140 | "Execute host and use supplied function to verify result." 141 | function execute(verify::Function, self::Tester, duration) 142 | @testset "$(self.name)" begin 143 | for host in Config.implementations 144 | # Compute expected storage root 145 | root = load_hash(self) 146 | 147 | # Run host long enough to load genesis 148 | result = run_tester(self, host, duration) 149 | 150 | verify((root, result)) 151 | end 152 | end # testset 153 | end 154 | 155 | end # module 156 | -------------------------------------------------------------------------------- /helpers/SpecificationTestsuite.jl: -------------------------------------------------------------------------------- 1 | module SpecificationTestsuite 2 | 3 | # Include general helpers 4 | include("StringHelpers.jl") 5 | 6 | 7 | export ALL_IMPLEMENTATIONS, ALL_FIXTURES, Config, execute 8 | 9 | "List of all known implementations" 10 | const ALL_IMPLEMENTATIONS = [ 11 | "substrate" 12 | "kagome" 13 | "gossamer" 14 | ] 15 | 16 | module Config 17 | import ..SpecificationTestsuite: ALL_IMPLEMENTATIONS 18 | import ..StringHelpers: StringList, CmdString, CmdStringList, cmdjoin 19 | 20 | "By default we log on a warning level." 21 | verbose = false 22 | 23 | "By default command are run on host." 24 | docker = false 25 | 26 | "Default containers to use in docker mode" 27 | containers = Dict{String,String}( 28 | "substrate" => "parity/polkadot:v0.8.5", 29 | #"kagome" => "docker.pkg.github.com/w3f/polkadot-spec/kagome:xxxxxxx", 30 | #"gossamer" => "docker.pkg.github.com/w3f/polkadot-spec/gossamer:xxxxxxx", 31 | ) 32 | 33 | "By default all implementations are enabled." 34 | implementations = ALL_IMPLEMENTATIONS 35 | 36 | "By default no additional arguments are passed." 37 | extra_args = `` 38 | 39 | "Path of folder containing all fixtures." 40 | function fixdir()::String 41 | return "$(@__DIR__)/../fixtures" 42 | end 43 | 44 | "All subfolders of the fixture folder (i.e. all available fixtures)." 45 | function fixsubdirs()::StringList 46 | return first(walkdir(fixdir()))[2] 47 | end 48 | 49 | "By default all fixtures are enabled." 50 | fixtures = fixsubdirs() 51 | 52 | "Update verbose setting in config" 53 | function set_verbose(enabled::Bool) 54 | global verbose = enabled 55 | end 56 | 57 | "Update selected implementations in config" 58 | function set_implementations(selected::StringList) 59 | global implementations = selected 60 | end 61 | 62 | "Update selected fixtures in config" 63 | function set_fixtures(selected::StringList) 64 | global fixtures = selected 65 | end 66 | 67 | "Update additional arguments to pass to executable" 68 | function set_extra_args(selected::CmdString) 69 | global extra_args = selected 70 | end 71 | 72 | "Update additional arguments to pass to executable" 73 | function set_extra_args(selected::CmdStringList) 74 | set_extra_args(cmdjoin(selected)) 75 | end 76 | 77 | "Update docker settings in config" 78 | function set_docker(enabled::Bool) 79 | global docker = enabled 80 | end 81 | 82 | "Retrieve docker image name to use in docker mode" 83 | function get_container(implementation::String)::String 84 | if !(implementation in ALL_IMPLEMENTATIONS) 85 | @error "Unknown implementation '$implementation'" 86 | end 87 | return get(containers, implementation, "") 88 | end 89 | end 90 | 91 | "List of all available fixtures" 92 | const ALL_FIXTURES = Config.fixsubdirs() 93 | 94 | # Include fixture helpers 95 | include("AdapterFixture.jl") 96 | include("HostFixture.jl") 97 | 98 | "Run specific fixture for configure implementations" 99 | function run_fixture(fixture::String) 100 | if !(fixture in ALL_FIXTURES) 101 | error("Unknown fixture: " * fixture) 102 | end 103 | 104 | @time include(Config.fixdir() * "/$fixture/include.jl") 105 | end 106 | 107 | "Run all configured fixtures" 108 | function execute() 109 | for fixture in Config.fixtures 110 | run_fixture(fixture) 111 | end 112 | end 113 | end 114 | 115 | -------------------------------------------------------------------------------- /helpers/StringHelpers.jl: -------------------------------------------------------------------------------- 1 | module StringHelpers 2 | 3 | export CmdList, CmdString, CmdStringList, CmdStringTuple, cmdjoin, cmdcombine 4 | export StringList, stringify, combine, inquotes, commajoin, flatzip 5 | export MaybeString, MaybeStringList 6 | 7 | using Base.Iterators 8 | 9 | "Base types used for list abstraction" 10 | List = Vector 11 | 12 | "List of lists" 13 | ListList{T} = List{List{T}} 14 | 15 | 16 | """ 17 | # Cmd collections and helper functions 18 | 19 | Thin wrapper around Julia's Cmd handeling _idioms_ for lists of commands and 20 | collections of those, as well as for the interaction with strings. 21 | """ 22 | 23 | "Simple command list abstraction." 24 | CmdList = List{Cmd} 25 | 26 | "A command or string" 27 | CmdString = Union{Cmd, String} 28 | 29 | "A list of command and strings" 30 | CmdStringList = Union{List{Cmd}, List{String}, List{CmdString}} 31 | 32 | "Any tuple of commands or strings" 33 | CmdStringTuple = Tuple{CmdString,Vararg{CmdString}} 34 | 35 | 36 | "Join two commands or strings with a space to a command" 37 | function cmdjoin(self::CmdString, other::CmdString)::Cmd 38 | return `$self $other` 39 | end 40 | 41 | "Combine all commands and strings in vector to single command, seperated by spaces." 42 | function cmdjoin(commands::CmdStringList)::Cmd 43 | return reduce(cmdjoin, commands) 44 | end 45 | 46 | "Combine all commands and strings in tuple to single command, seperated by spaces." 47 | function cmdjoin(commands::CmdStringTuple)::Cmd 48 | return reduce(cmdjoin, commands) 49 | end 50 | 51 | 52 | "Helper to append commands or strings to all entries of a list." 53 | function cmdcombine(self::CmdStringList, suffix::CmdString)::CmdList 54 | return map((x)->cmdjoin(x, suffix), self) 55 | end 56 | 57 | "Helper to append each member of another list to all entries of current list." 58 | function cmdcombine(self::CmdStringList, other::CmdStringList)::CmdList 59 | # For the resulting vector to be in the user expected order the two 60 | # lists are multiplied in reversed order, while the string are joined 61 | # in the correct order. 62 | # Could be replace by transpose operation but Julia seems to be lacking 63 | # transpose(Matrix{String}), though onw could use `permutedims`. 64 | return vec(map(cmdjoin ∘ reverse, product(other, self))) 65 | end 66 | 67 | 68 | """ 69 | # String collections and helper functions 70 | 71 | Thin wrapper around Julia's String handeling _idioms_ for lists of strings and 72 | collections of those. 73 | """ 74 | 75 | "Simple string list abstraction." 76 | StringList = List{String} 77 | 78 | "Ordered collection of string lists." 79 | StringListList = List{StringList} 80 | 81 | 82 | "Turn parameter set into a pure string representation." 83 | function stringify(self::ListList{<:Any})::StringListList 84 | map(xs -> map(string, xs), self) 85 | end 86 | 87 | "Helper to append string to all entries of a list." 88 | function combine(self::StringList, suffix::String)::StringList 89 | return self .* suffix 90 | end 91 | 92 | "Helper to append each member of a different list to all entries." 93 | function combine(self::StringList, other::StringList)::StringList 94 | # For the resulting vector to be in the user expected order the two 95 | # lists are multiplied in reversed order, while the string are joined 96 | # in the correct order. 97 | # Could be replace by transpose operation but Julia seems to be lacking 98 | # transpose(Matrix{String}), though onw could use `permutedims`. 99 | return vec(map(join ∘ reverse, product(other, self))) 100 | end 101 | 102 | "Helper to put each string in list inside double quotes." 103 | function inquotes(self::StringList)::StringList 104 | return "\"" .* self .* "\"" 105 | end 106 | 107 | "Helper to join a list of strings with commas." 108 | function commajoin(self::StringList)::String 109 | return join(self, ",") 110 | end 111 | 112 | "Helper to join all string lists inside a collectin with commas." 113 | function commajoin(self::StringListList)::StringList 114 | return map(commajoin, self) 115 | end 116 | 117 | "Helper to join all parameter lists inside a collection with commas." 118 | function commajoin(self::ListList{<:Any})::StringList 119 | self |> stringify |> commajoin 120 | end 121 | 122 | 123 | """ 124 | # String-or-nothing collections 125 | """ 126 | 127 | "A string (even empty) or nothing" 128 | MaybeString = Union{String, Nothing} 129 | 130 | "Simple string-or-nothing list abstraction." 131 | MaybeStringList = Union{List{MaybeString}, List{String}, List{Nothing}} 132 | 133 | 134 | "Convert StringList to MaybeStringList" 135 | Base.convert(::Type{MaybeStringList}, from::List{String}) = List{MaybeString}(from) 136 | 137 | "Convert NothingList to MaybeStringList" 138 | Base.convert(::Type{MaybeStringList}, from::List{Nothing}) = List{MaybeString}(from) 139 | 140 | 141 | #"Construct MaybeStringList from empty list" 142 | Union{List{MaybeString}, List{String}, List{Nothing}}(list::List{Any}) = List{MaybeString}(list) 143 | 144 | #"Construct MaybeStringList by filling it with MaybeString" 145 | Union{List{MaybeString}, List{String}, List{Nothing}}(v::MaybeString, n::Int64) = List{MaybeString}(v, n) 146 | 147 | 148 | """ 149 | # General collection helper functions 150 | """ 151 | 152 | """ 153 | flatzip(dataset_1, dataset_2, ...) 154 | 155 | Helper to zip together multiple collections of parameter lists into a single 156 | collection. 157 | 158 | # Description 159 | Combines the inner arrays of the different test data types, iterates over them, 160 | and merges those arrays of each iteration into a single, new array. 161 | This allows to reuse test data for functions of various input types. 162 | 163 | # Example 164 | ```jldoctest 165 | julia> flatzip( \\ 166 | # Test data type (each inner array represents different values) \\ 167 | [[1, 2, 3], [7, 8, 9], [13, 14, 15]], \\ 168 | # Different test data type (each inner array represents different values) \\ 169 | [[4, 5, 6], [10, 11, 12], [16, 17, 18]], \\ 170 | ) 171 | 3-element Array{Array{Int,1},1}: 172 | [1, 2, 3, 4, 5, 6] 173 | [7, 8, 9, 10, 11, 12] 174 | [13, 14, 15, 16, 17, 18] 175 | ``` 176 | """ 177 | function flatzip(self::ListList{<:Any}...)::ListList{<:Any} 178 | return map(collect ∘ flatten, zip(self...)) 179 | end 180 | 181 | end # module 182 | -------------------------------------------------------------------------------- /hosts/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all substrate kagome gossamer sync-substrate sync-adapter-substrate sync-runtime-tester sync-gossamer sync-adapter-gossamer version clean 2 | 3 | 4 | all: substrate kagome gossamer 5 | 6 | 7 | substrate: 8 | cd substrate && SKIP_WASM_BUILD=1 cargo build --release 9 | cp substrate/target/release/polkadot ../bin/ 10 | 11 | kagome: 12 | cmake -DCMAKE_BUILD_TYPE=Release -DHUNTER_CONFIGURATION_TYPES=Release \ 13 | -DHUNTER_PASSWORDS_PATH="$(CURDIR)/../adapters/kagome/cmake/HunterPasswords.cmake" \ 14 | -DHUNTER_CACHE_SERVERS="https://github.com/w3f/hunter-binary-cache" \ 15 | -DTESTING=OFF -S kagome -B kagome/build 16 | cmake --build kagome/build 17 | cp kagome/build/node/kagome ../bin/ 18 | 19 | gossamer: 20 | cd gossamer && go build -v ./cmd/gossamer 21 | cp gossamer/gossamer ../bin/ 22 | cp ~/go/pkg/mod/github.com/wasmerio/go-ext-wasm@*/wasmer/libwasmer.so ../lib/ 23 | chmod u+w ../lib/libwasmer.so 24 | 25 | 26 | sync-substrate: sync-adapter-substrate sync-runtime-tester 27 | 28 | sync-adapter-substrate: 29 | cp substrate/Cargo.lock ../adapters/substrate/ 30 | cargo metadata --manifest-path ../adapters/substrate/Cargo.toml --format-version 1 > /dev/null 31 | 32 | sync-runtime-tester: 33 | cp substrate/Cargo.lock ../runtimes/tester 34 | cargo metadata --manifest-path ../runtimes/tester/Cargo.toml --format-version 1 > /dev/null 35 | 36 | 37 | sync-gossamer: sync-adapter-gossamer 38 | 39 | sync-adapter-gossamer: 40 | cd ../adapters/gossamer && go mod tidy 41 | 42 | 43 | version: 44 | @echo "substrate-host: $$(cd substrate && git describe)" 45 | @echo "kagome-host: $$(cd kagome && git describe)" 46 | @echo "gossamer-host: $$(cd gossamer && git describe --tags)" 47 | 48 | clean: 49 | rm -rf substrate/target 50 | rm -rf kagome/build 51 | rm -f gossamer/gossamer 52 | -------------------------------------------------------------------------------- /runtests.jl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env julia 2 | 3 | include("helpers/SpecificationTestsuite.jl") 4 | 5 | using .SpecificationTestsuite 6 | 7 | 8 | function print_usage() 9 | println("usage: $PROGRAM_FILE [OPTIONS] [FILTERS ...] --args [ARGS ...]") 10 | println() 11 | println("OPTIONS:") 12 | println(" --help Display this message") 13 | println(" --verbose Print debug information") 14 | println(" --docker Use docker containers instead of local builds.") 15 | println() 16 | println("FILTERS:") 17 | println("A filter can be used to run specific implementations or fixtures.") 18 | println("If none are provided all are run. Multiple selecetions are possible.") 19 | println() 20 | println("IMPLEMENTATIONS:") 21 | println(join(ALL_IMPLEMENTATIONS, ", ")) 22 | println() 23 | println("FIXTURES:") 24 | println(join(ALL_FIXTURES, ", ")) 25 | println() 26 | println("EXTRA ARGUMENTS:") 27 | println("To run the underlying adapter or host with additional arguments, any extra") 28 | println("arguments passed after --args will be forwarded to the binary.") 29 | end 30 | 31 | 32 | # Collect filters 33 | implementations = Vector{String}() 34 | fixtures = Vector{String}() 35 | 36 | # Collect additional arguments 37 | forward_args = false 38 | extra_args = Vector{String}() 39 | 40 | # Process all command line arguments 41 | for arg in ARGS 42 | 43 | if forward_args 44 | push!(extra_args, arg) 45 | continue 46 | end 47 | 48 | if arg == "--help" 49 | print_usage() 50 | exit() 51 | end 52 | 53 | if arg == "--verbose" 54 | Config.set_verbose(true) 55 | continue 56 | end 57 | 58 | if arg == "--docker" 59 | Config.set_docker(true) 60 | continue 61 | end 62 | 63 | if arg == "--args" 64 | global forward_args = true 65 | continue 66 | end 67 | 68 | if arg in ALL_IMPLEMENTATIONS 69 | push!(implementations, arg) 70 | continue 71 | end 72 | 73 | if arg in ALL_FIXTURES 74 | push!(fixtures, arg) 75 | continue 76 | end 77 | 78 | println("Unknown argument: ", arg) 79 | println() 80 | print_usage() 81 | exit() 82 | end 83 | 84 | # Apply any specified filters 85 | if !isempty(implementations) 86 | Config.set_implementations(implementations) 87 | end 88 | 89 | if !isempty(fixtures) 90 | Config.set_fixtures(fixtures) 91 | end 92 | 93 | # Forward any extra flags 94 | if !isempty(extra_args) 95 | Config.set_extra_args(extra_args) 96 | end 97 | 98 | # Display config 99 | println("CONFIGURATION:") 100 | println("Loglevel: " * (Config.verbose ? "verbose" : "info")) 101 | println("Binaries: " * (Config.docker ? "container" : "local")) 102 | println("Implementations: " * join(Config.implementations, ", ")) 103 | println("Fixtures: " * join(Config.fixtures, ", ")) 104 | println("Extra Arguments: " * string(Config.extra_args)) 105 | println() 106 | 107 | # Add locally build or downloaded adapters, testers and hosts to PATH 108 | ENV["PATH"] *= ":$(@__DIR__)/bin" 109 | 110 | # Add locally build libaries, because gossamer wasmer go extension does not 111 | # support static linking yet and depends on libwasmer.so. 112 | # https://github.com/wasmerio/go-ext-wasm/pull/40 113 | if haskey(ENV, "LD_LIBRARY_PATH") 114 | ENV["LD_LIBRARY_PATH"] *= ":$(@__DIR__)/lib" 115 | else 116 | ENV["LD_LIBRARY_PATH"] = "$(@__DIR__)/lib" 117 | end 118 | 119 | # Run from this subfolder (to allow relative paths in suite) 120 | previous_path = pwd() 121 | cd("$(@__DIR__)") 122 | 123 | # Execute config 124 | println("EXECUTION:") 125 | execute() 126 | 127 | # Reset path 128 | cd(previous_path) 129 | 130 | exit() 131 | -------------------------------------------------------------------------------- /runtimes/hostapi/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /runtimes/hostapi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hostapi-runtime" 3 | version = "3.0.0" 4 | edition = "2018" 5 | build = "build.rs" 6 | 7 | [dependencies] 8 | sp-core = { version = "9.0", default-features = false, optional = true } 9 | parity-scale-codec = { version = "3.4", default-features = false, optional = true } 10 | 11 | [build-dependencies] 12 | substrate-wasm-builder = "3.0" 13 | 14 | [features] 15 | std = [ "sp-core/std", "parity-scale-codec/std" ] 16 | runtime-wasm = [ "sp-core", "parity-scale-codec" ] 17 | vendor-fix = [ "sp-core", "parity-scale-codec" ] 18 | export-memory = [] 19 | -------------------------------------------------------------------------------- /runtimes/hostapi/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all build install build-expmem install-expmem version clean 2 | 3 | RELEASE_WASM_PATH := target/release/wbuild/hostapi-runtime/hostapi_runtime.compact.wasm 4 | 5 | 6 | all: install 7 | 8 | build: 9 | cargo build --release 10 | 11 | install: build 12 | cp $(RELEASE_WASM_PATH) ../../bin/hostapi-runtime.default.wasm 13 | 14 | 15 | build-expmem: 16 | cargo build --features export-memory --release 17 | 18 | install-expmem: build-expmem 19 | cp $(RELEASE_WASM_PATH) ../../bin/hostapi-runtime.expmem.wasm 20 | 21 | 22 | version: 23 | @echo "Unknown" 24 | 25 | clean: 26 | rm -rf target 27 | -------------------------------------------------------------------------------- /runtimes/hostapi/build.rs: -------------------------------------------------------------------------------- 1 | use substrate_wasm_builder::WasmBuilder; 2 | 3 | fn main() { 4 | let mut b = WasmBuilder::new() 5 | .with_current_project() 6 | .export_heap_base(); 7 | 8 | if !cfg!(feature = "export-memory") { 9 | b = b.import_memory(); 10 | } 11 | 12 | b.build() 13 | } 14 | -------------------------------------------------------------------------------- /runtimes/hostapi/default.nix: -------------------------------------------------------------------------------- 1 | { polkadot-tests, naersk }: 2 | 3 | naersk.buildPackage rec { 4 | name = "hostapi-runtime"; 5 | inherit (polkadot-tests) version; 6 | 7 | src = "${polkadot-tests.src}/runtimes/hostapi"; 8 | 9 | overrideMain = _: { 10 | name = "hostapi-runtime-${version}.default.wasm"; 11 | 12 | installPhase = '' 13 | cp target/release/wbuild/hostapi-runtime/hostapi_runtime.compact.wasm $out 14 | ''; 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /runtimes/hostapi/shell.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem }: 2 | 3 | (builtins.getFlake "git+file:./../..").devShells.${system}.substrate 4 | -------------------------------------------------------------------------------- /runtimes/tester/.gitignore: -------------------------------------------------------------------------------- 1 | /runtime/Cargo.lock 2 | /target/ 3 | genesis.*.hash 4 | genesis.*.json 5 | -------------------------------------------------------------------------------- /runtimes/tester/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = 'host-tester' 3 | edition.workspace = true 4 | version.workspace = true 5 | 6 | [workspace.package] 7 | edition = '2021' 8 | version = "0.9.31-f0e1ed0" 9 | 10 | [profile.release] 11 | panic = 'unwind' 12 | 13 | 14 | [dependencies.tester-runtime] 15 | path = "runtime" 16 | 17 | [dependencies.sc-service] 18 | git = "https://github.com/paritytech/substrate" 19 | branch = "master" 20 | default-features = false 21 | 22 | [dependencies.sp-core] 23 | git = "https://github.com/paritytech/substrate" 24 | branch = "master" 25 | default-features = false 26 | 27 | [dependencies.sp-runtime] 28 | git = "https://github.com/paritytech/substrate" 29 | branch = "master" 30 | default-features = false 31 | 32 | [dependencies.sp-babe] 33 | package = 'sp-consensus-babe' 34 | git = "https://github.com/paritytech/substrate" 35 | branch = "master" 36 | default-features = false 37 | 38 | [dependencies.sp-grandpa] 39 | package = 'sp-finality-grandpa' 40 | git = "https://github.com/paritytech/substrate" 41 | branch = "master" 42 | default-features = false 43 | 44 | [features] 45 | legacy = [ "tester-runtime/legacy" ] 46 | 47 | [workspace] 48 | members = [ "runtime" ] 49 | -------------------------------------------------------------------------------- /runtimes/tester/Makefile: -------------------------------------------------------------------------------- 1 | # Default targets 2 | TARGETS_DEFAULT := hash json 3 | TARGETS_LEGACY := $(patsubst %,%-legacy,$(TARGETS_DEFAULT)) 4 | 5 | default: $(TARGETS_DEFAULT) 6 | 7 | legacy: $(TARGETS_LEGACY) 8 | 9 | .PHONY: .FORCE default legacy $(TARGETS_DEFAULT) $(TARGETS_LEGACY) version clean 10 | .FORCE: # Always run cargo to check for changes 11 | 12 | # Plain version, no features 13 | OUTPUTS_DEFAULT := $(patsubst %,genesis.default.%,$(TARGETS_DEFAULT)) 14 | 15 | $(TARGETS_DEFAULT): %: genesis.default.% 16 | 17 | $(OUTPUTS_DEFAULT): genesis.default.%: .FORCE 18 | cargo run --release $* > $@ 19 | 20 | # Legacy state storage version 21 | OUTPUTS_LEGACY := $(patsubst %,genesis.legacy.%,$(TARGETS_DEFAULT)) 22 | 23 | $(TARGETS_LEGACY): %-legacy: genesis.legacy.% 24 | 25 | $(OUTPUTS_LEGACY): genesis.legacy.%: .FORCE 26 | cargo run --release --features legacy $* > $@ 27 | 28 | # Targets for developers 29 | version: 30 | @cargo metadata --format-version 1 | jq '.packages[] | select(.name=="sp-core").id' | cut -d' ' -f2 31 | 32 | clean: 33 | $(RM) -r target genesis.{default,legacy}.{hash,json} 34 | -------------------------------------------------------------------------------- /runtimes/tester/default.nix: -------------------------------------------------------------------------------- 1 | { polkadot-tests, naersk, protobuf }: 2 | 3 | naersk.buildPackage { 4 | pname = "tester-runtime"; 5 | inherit (polkadot-tests) version; 6 | 7 | src = "${polkadot-tests.src}/runtimes/tester"; 8 | 9 | # Needed to build rust-libp2p 10 | PROTOC = "${protobuf}/bin/protoc"; 11 | } 12 | -------------------------------------------------------------------------------- /runtimes/tester/gossamer.config.toml: -------------------------------------------------------------------------------- 1 | [global] 2 | id = "spectest" 3 | 4 | [core] 5 | roles = 4 6 | babe-authority = true 7 | grandpa-authority = true 8 | 9 | [network] 10 | nobootstrap = true 11 | nomdns = true 12 | 13 | [rpc] 14 | enabled = false 15 | 16 | [pprof] 17 | enabled = false 18 | -------------------------------------------------------------------------------- /runtimes/tester/keystore/babed43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d: -------------------------------------------------------------------------------- 1 | e5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a -------------------------------------------------------------------------------- /runtimes/tester/keystore/gran88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee: -------------------------------------------------------------------------------- 1 | abf8e5bdbe30c65656c0a3cbd181ff8a56294a69dfedd27982aace4a76909115 -------------------------------------------------------------------------------- /runtimes/tester/keystore/lp2p48453469c62f4885373099421a7365520b5ffb0d93726c124166be4b81d852e6: -------------------------------------------------------------------------------- 1 | 4a9361c525840f7086b893d584ebbe475b4ec7069951d2e897e8bceb0a3f35ce -------------------------------------------------------------------------------- /runtimes/tester/runtime/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = 'tester-runtime' 3 | version.workspace = true 4 | edition.workspace = true 5 | 6 | 7 | [dependencies.hex] 8 | version = '0.4.2' 9 | default-features = false 10 | 11 | 12 | # Base dependencies 13 | [dependencies.serde] 14 | version = '1.0.101' 15 | features = ['derive'] 16 | optional = true 17 | 18 | [dependencies.codec] 19 | package = 'parity-scale-codec' 20 | version = '3.0.0' 21 | default-features = false 22 | features = ['derive'] 23 | 24 | [dependencies.scale-info] 25 | version = '2.1.1' 26 | default-features = false 27 | features = ['derive'] 28 | 29 | 30 | # Substrate FRAME is the basis 31 | [dependencies.frame-executive] 32 | git = "https://github.com/paritytech/substrate" 33 | branch = "master" 34 | default-features = false 35 | 36 | [dependencies.frame-support] 37 | git = "https://github.com/paritytech/substrate" 38 | branch = "master" 39 | default-features = false 40 | 41 | 42 | # Substrate pallet to provide runtime basics 43 | [dependencies.system] 44 | git = "https://github.com/paritytech/substrate" 45 | branch = "master" 46 | package = 'frame-system' 47 | default-features = false 48 | 49 | [dependencies.collective-flip] 50 | package = 'pallet-randomness-collective-flip' 51 | git = "https://github.com/paritytech/substrate" 52 | branch = "master" 53 | default-features = false 54 | 55 | [dependencies.timestamp] 56 | package = 'pallet-timestamp' 57 | git = "https://github.com/paritytech/substrate" 58 | branch = "master" 59 | default-features = false 60 | 61 | 62 | # Polkadot consensus and finality 63 | [dependencies.babe] 64 | package = 'pallet-babe' 65 | git = "https://github.com/paritytech/substrate" 66 | branch = "master" 67 | default-features = false 68 | 69 | [dependencies.grandpa] 70 | package = 'pallet-grandpa' 71 | git = "https://github.com/paritytech/substrate" 72 | branch = "master" 73 | default-features = false 74 | 75 | 76 | # TODO Only enabled via feature flag? 77 | [dependencies.balances] 78 | package = 'pallet-balances' 79 | git = "https://github.com/paritytech/substrate" 80 | branch = "master" 81 | default-features = false 82 | 83 | # TODO Only enabled via feature flag? 84 | [dependencies.sudo] 85 | package = 'pallet-sudo' 86 | git = "https://github.com/paritytech/substrate" 87 | branch = "master" 88 | default-features = false 89 | 90 | 91 | # List of required substrate primitives (sp) 92 | [dependencies.sp-api] 93 | git = "https://github.com/paritytech/substrate" 94 | branch = "master" 95 | default-features = false 96 | 97 | [dependencies.sp-block-builder] 98 | git = "https://github.com/paritytech/substrate" 99 | branch = "master" 100 | default-features = false 101 | 102 | [dependencies.sp-core] 103 | git = "https://github.com/paritytech/substrate" 104 | branch = "master" 105 | default-features = false 106 | 107 | [dependencies.sp-inherents] 108 | git = "https://github.com/paritytech/substrate" 109 | branch = "master" 110 | default-features = false 111 | 112 | [dependencies.sp-io] 113 | git = "https://github.com/paritytech/substrate" 114 | branch = "master" 115 | default-features = false 116 | 117 | [dependencies.sp-runtime] 118 | git = "https://github.com/paritytech/substrate" 119 | branch = "master" 120 | default-features = false 121 | 122 | [dependencies.sp-std] 123 | git = "https://github.com/paritytech/substrate" 124 | branch = "master" 125 | default-features = false 126 | 127 | [dependencies.sp-transaction-pool] 128 | git = "https://github.com/paritytech/substrate" 129 | branch = "master" 130 | default-features = false 131 | 132 | [dependencies.sp-version] 133 | git = "https://github.com/paritytech/substrate" 134 | branch = "master" 135 | default-features = false 136 | 137 | [dependencies.sp-session] 138 | git = "https://github.com/paritytech/substrate" 139 | branch = "master" 140 | default-features = false 141 | 142 | [dependencies.sp-babe] 143 | package = 'sp-consensus-babe' 144 | git = "https://github.com/paritytech/substrate" 145 | branch = "master" 146 | default-features = false 147 | 148 | [dependencies.sp-grandpa] 149 | package = 'sp-finality-grandpa' 150 | git = "https://github.com/paritytech/substrate" 151 | branch = "master" 152 | default-features = false 153 | 154 | 155 | [build-dependencies.wasm-builder] 156 | package = 'substrate-wasm-builder' 157 | version = '3.0.0' 158 | 159 | 160 | [features] 161 | default = ['std'] 162 | # Propagate std flag if set 163 | std = [ 164 | 'serde', 165 | 'codec/std', 166 | 'frame-executive/std', 167 | 'frame-support/std', 168 | 'system/std', 169 | 'collective-flip/std', 170 | 'babe/std', 171 | 'grandpa/std', 172 | 'balances/std', 173 | 'sudo/std', 174 | 'sp-api/std', 175 | 'sp-block-builder/std', 176 | 'sp-core/std', 177 | 'sp-inherents/std', 178 | 'sp-io/std', 179 | 'sp-runtime/std', 180 | 'sp-std/std', 181 | 'sp-transaction-pool/std', 182 | 'sp-version/std', 183 | 'sp-session/std', 184 | 'sp-babe/std', 185 | 'sp-grandpa/std', 186 | ] 187 | # Use legacy state version 188 | legacy = [] 189 | -------------------------------------------------------------------------------- /runtimes/tester/runtime/build.rs: -------------------------------------------------------------------------------- 1 | use wasm_builder::WasmBuilder; 2 | 3 | fn main() { 4 | WasmBuilder::new() 5 | .with_current_project() 6 | .export_heap_base() 7 | .import_memory() 8 | .build() 9 | } 10 | -------------------------------------------------------------------------------- /runtimes/tester/shell.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem }: 2 | 3 | (builtins.getFlake "git+file:./../..").devShells.${system}.substrate 4 | -------------------------------------------------------------------------------- /runtimes/tester/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use tester_runtime::{ 4 | AccountId, BabeConfig, BalancesConfig, GenesisConfig, 5 | GrandpaConfig, SudoConfig, SystemConfig, BuildStorage, Header, 6 | Signature, BABE_GENESIS_EPOCH_CONFIG, STATE_VERSION, WASM_BINARY, 7 | }; 8 | 9 | use sp_core::{H256, Pair, Public, sr25519}; 10 | use sc_service::{GenericChainSpec, ChainType}; 11 | use sp_runtime::traits::{ 12 | Hash as HashT, Header as HeaderT, 13 | Verify, IdentifyAccount 14 | }; 15 | 16 | use sp_babe::AuthorityId as BabeId; 17 | use sp_grandpa::AuthorityId as GrandpaId; 18 | 19 | /// Specialized `ChainSpec` of the general Substrate ChainSpec type. 20 | type ChainSpec = GenericChainSpec; 21 | 22 | /// Helper function to generate a crypto pair from seed 23 | fn get_from_seed(seed: &str) -> ::Public { 24 | TPublic::Pair::from_string(&format!("//{}", seed), None) 25 | .expect("static values are valid; qed") 26 | .public() 27 | } 28 | 29 | type AccountPublic = ::Signer; 30 | 31 | /// Helper function to generate an account ID from seed 32 | fn get_account_id_from_seed(seed: &str) -> AccountId where 33 | AccountPublic: From<::Public> 34 | { 35 | AccountPublic::from(get_from_seed::(seed)).into_account() 36 | } 37 | 38 | 39 | /// Create default genesis config 40 | fn default_genesis_config() -> GenesisConfig { 41 | GenesisConfig { 42 | system: SystemConfig { 43 | code: WASM_BINARY.unwrap().to_vec(), 44 | }, 45 | balances: BalancesConfig { 46 | balances: vec![ 47 | get_account_id_from_seed::("Alice"), 48 | get_account_id_from_seed::("Bob"), 49 | get_account_id_from_seed::("Alice//stash"), 50 | get_account_id_from_seed::("Bob//stash"), 51 | ].iter().cloned().map(|k|(k, 1 << 60)).collect(), 52 | }, 53 | babe: BabeConfig { 54 | authorities: vec![ 55 | (get_from_seed::("Alice"), 1), 56 | (get_from_seed::("Bob"), 1), 57 | ], 58 | epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG), 59 | }, 60 | grandpa: GrandpaConfig { 61 | authorities: vec![ 62 | (get_from_seed::("Alice"), 1), 63 | (get_from_seed::("Bob"), 1), 64 | ], 65 | }, 66 | sudo: SudoConfig { 67 | key: Some(get_account_id_from_seed::("Alice")), 68 | }, 69 | } 70 | } 71 | 72 | /// Compute genesis hash 73 | fn default_genesis_hash() -> H256 { 74 |
::Hashing::trie_root( 75 | default_genesis_config().build_storage().unwrap().top.into_iter().collect(), 76 | STATE_VERSION 77 | ) 78 | } 79 | 80 | /// Create default chain specification 81 | fn default_chain_spec() -> ChainSpec { 82 | ChainSpec::from_genesis( 83 | "Specification Conformance Test", 84 | "spectest", 85 | ChainType::Development, 86 | default_genesis_config, 87 | vec![], // Bootnodes 88 | None, // Telemetry 89 | None, // Protocol Id 90 | None, // Fork Id 91 | None, // Properties 92 | None, // Extensions 93 | ) 94 | } 95 | 96 | 97 | /// Print storage root hash of genesis 98 | fn print_genesis_hash() { 99 | print!("{:x}", default_genesis_hash()); 100 | } 101 | 102 | /// Print chain spec of tester chain 103 | fn print_chain_spec() { 104 | match default_chain_spec().as_json(true) { 105 | Ok(json) => println!("{}", json), 106 | Err(err) => eprintln!("Error: {}", err), 107 | } 108 | } 109 | 110 | 111 | /// Print command line help 112 | fn print_usage() { 113 | println!("usage: host-tester {{hash|json}}"); 114 | } 115 | 116 | /// Entry point, parses command line arguments 117 | fn main() { 118 | let args: Vec = env::args().collect(); 119 | 120 | if args.len() == 2 { 121 | match &args[1][..] { 122 | "hash" => print_genesis_hash(), 123 | "json" => print_chain_spec(), 124 | _ => print_usage(), 125 | } 126 | } else { 127 | print_usage(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "nightly-2022-11-15" 3 | targets = [ "wasm32-unknown-unknown" ] 4 | --------------------------------------------------------------------------------