From 4fc8a38e5f8246358fa02bd3ea609390ddb7a6d1 Mon Sep 17 00:00:00 2001 From: sotmorskiy Date: Wed, 23 Sep 2020 10:10:35 +0000 Subject: [PATCH] NFTPAR-93 SIT: Flipper smart contract can be deployed, getting of value works, flipping works. --- --- /dev/null +++ b/purge-running-node.sh @@ -0,0 +1,3 @@ +docker-compose exec node nft purge-chain --dev --base-path=/chain-data -y +docker-compose down +docker-compose up -d --- /dev/null +++ b/tests/flipper-src/.gitignore @@ -0,0 +1,9 @@ +# Ignore build artifacts from the local tests sub-crate. +/target/ + +# Ignore backup files creates by cargo fmt. +**/*.rs.bk + +# Remove Cargo.lock when creating an executable, leave it for libraries +# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock +Cargo.lock --- /dev/null +++ b/tests/flipper-src/.ink/abi_gen/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "abi-gen" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +publish = false + +[[bin]] +name = "abi-gen" +path = "main.rs" + +[dependencies] +contract = { path = "../..", package = "flipper", default-features = false, features = ["ink-generate-abi"] } +ink_lang = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_lang", default-features = false, features = ["ink-generate-abi"] } +serde = "1.0" +serde_json = "1.0" --- /dev/null +++ b/tests/flipper-src/.ink/abi_gen/main.rs @@ -0,0 +1,7 @@ +fn main() -> Result<(), std::io::Error> { + let abi = ::generate_abi(); + let contents = serde_json::to_string_pretty(&abi)?; + std::fs::create_dir("target").ok(); + std::fs::write("target/metadata.json", contents)?; + Ok(()) +} --- /dev/null +++ b/tests/flipper-src/Cargo.toml @@ -0,0 +1,67 @@ +[package] +name = "flipper" +version = "0.1.0" +authors = ["[your_name] <[your_email]>"] +edition = "2018" + +[dependencies] +ink_abi = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_abi", default-features = false, features = ["derive"], optional = true } +ink_primitives = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_primitives", default-features = false } +ink_core = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_core", default-features = false } +ink_lang = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_lang", default-features = false } + +scale = { package = "parity-scale-codec", version = "1.2", default-features = false, features = ["derive"] } + +[dependencies.type-metadata] +git = "https://github.com/type-metadata/type-metadata.git" +rev = "02eae9f35c40c943b56af5b60616219f2b72b47d" +default-features = false +features = ["derive"] +optional = true + +[lib] +name = "flipper" +path = "lib.rs" +crate-type = [ + # Used for normal contract Wasm blobs. + "cdylib", + # Required for ABI generation, and using this contract as a dependency. + # If using `cargo contract build`, it will be automatically disabled to produce a smaller Wasm binary + "rlib", +] + +[features] +default = ["test-env"] +std = [ + "ink_abi/std", + "ink_core/std", + "ink_primitives/std", + "scale/std", + "type-metadata/std", +] +test-env = [ + "std", + "ink_lang/test-env", +] +ink-generate-abi = [ + "std", + "ink_abi", + "type-metadata", + "ink_core/ink-generate-abi", + "ink_lang/ink-generate-abi", +] +ink-as-dependency = [] + +[profile.release] +panic = "abort" +lto = true +opt-level = "z" +overflow-checks = true + +[workspace] +members = [ + ".ink/abi_gen" +] +exclude = [ + ".ink" +] --- /dev/null +++ b/tests/flipper-src/build.sh @@ -0,0 +1,2 @@ +cargo +nightly contract build +cargo +nightly contract generate-metadata --- /dev/null +++ b/tests/flipper-src/lib.rs @@ -0,0 +1,76 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +use ink_lang as ink; + +#[ink::contract(version = "0.1.0")] +mod flipper { + use ink_core::storage; + + /// Defines the storage of your contract. + /// Add new fields to the below struct in order + /// to add new static storage fields to your contract. + #[ink(storage)] + struct Flipper { + /// Stores a single `bool` value on the storage. + value: storage::Value, + } + + impl Flipper { + /// Constructor that initializes the `bool` value to the given `init_value`. + #[ink(constructor)] + fn new(&mut self, init_value: bool) { + self.value.set(init_value); + } + + /// Constructor that initializes the `bool` value to `false`. + /// + /// Constructors can delegate to other constructors. + #[ink(constructor)] + fn default(&mut self) { + self.new(false) + } + + /// A message that can be called on instantiated contracts. + /// This one flips the value of the stored `bool` from `true` + /// to `false` and vice versa. + #[ink(message)] + fn flip(&mut self) { + *self.value = !self.get(); + } + + /// Simply returns the current value of our `bool`. + #[ink(message)] + fn get(&self) -> bool { + *self.value + } + } + + /// Unit tests in Rust are normally defined within such a `#[cfg(test)]` + /// module and test functions are marked with a `#[test]` attribute. + /// The below code is technically just normal Rust code. + #[cfg(test)] + mod tests { + /// Imports all the definitions from the outer scope so we can use them here. + use super::*; + + /// We test if the default constructor does its job. + #[test] + fn default_works() { + // Note that even though we defined our `#[ink(constructor)]` + // above as `&mut self` functions that return nothing we can call + // them in test code as if they were normal Rust constructors + // that take no `self` argument but return `Self`. + let flipper = Flipper::default(); + assert_eq!(flipper.get(), false); + } + + /// We test a simple use case of our contract. + #[test] + fn it_works() { + let mut flipper = Flipper::new(false); + assert_eq!(flipper.get(), false); + flipper.flip(); + assert_eq!(flipper.get(), true); + } + } +} --- a/tests/package-lock.json +++ b/tests/package-lock.json @@ -3916,60 +3916,195 @@ } }, "@polkadot/api": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/api/-/api-1.31.2.tgz", - "integrity": "sha512-5nMraRQYFt+xeInQi5i7c00fwOiSeZgU3Y1LJWz+z+Vnxep7xzjVBMLgBi4fe7g2eWKUYB79ApFNV8r2thsQZg==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/api/-/api-1.34.1.tgz", + "integrity": "sha512-3gCibNRchH+XbEdULS1bwiV1RgarZW1PDw1Y1mAQBVqPrUpkYqntp1D52SQOpAbRzldkwk296Sj+mx9/IeDRXA==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/api-derive": "1.31.2", + "@polkadot/api-derive": "1.34.1", "@polkadot/keyring": "^3.4.1", - "@polkadot/metadata": "1.31.2", - "@polkadot/rpc-core": "1.31.2", - "@polkadot/rpc-provider": "1.31.2", - "@polkadot/types": "1.31.2", - "@polkadot/types-known": "1.31.2", + "@polkadot/metadata": "1.34.1", + "@polkadot/rpc-core": "1.34.1", + "@polkadot/rpc-provider": "1.34.1", + "@polkadot/types": "1.34.1", + "@polkadot/types-known": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "bn.js": "^5.1.3", - "eventemitter3": "^4.0.6", - "rxjs": "^6.6.2" + "eventemitter3": "^4.0.7", + "rxjs": "^6.6.3" }, "dependencies": { "@polkadot/metadata": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.31.2.tgz", - "integrity": "sha512-UAcZLxh6QFwhF2Ccmax6LUYa99NntBZrAe8oUN92UJlHbtAutd5sq322P+liG2EHfyhUZs5T5v8jLD79pMTjdA==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.34.1.tgz", + "integrity": "sha512-uoaOhNHjECDaLBYvGRaLvF0mhZBFmsV3oikYDP4sZx3a5oD0xYsyXtr5bFPQDImwPFASP8/ltrMVqcYTX42xFg==", + "requires": { + "@babel/runtime": "^7.11.2", + "@polkadot/types": "1.34.1", + "@polkadot/types-known": "1.34.1", + "@polkadot/util": "^3.4.1", + "@polkadot/util-crypto": "^3.4.1", + "bn.js": "^5.1.3" + } + }, + "@polkadot/types": { + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.34.1.tgz", + "integrity": "sha512-jPwix2y+ZXKYB4ghODXlqYmcI3Tnsl3iO3xIkiGsZhhs9PdrKibcNeAv4LUiRpPuGRnAM+mrlPrBbCuzguKSGg==", + "requires": { + "@babel/runtime": "^7.11.2", + "@polkadot/metadata": "1.34.1", + "@polkadot/util": "^3.4.1", + "@polkadot/util-crypto": "^3.4.1", + "@types/bn.js": "^4.11.6", + "bn.js": "^5.1.3", + "memoizee": "^0.4.14", + "rxjs": "^6.6.3" + } + }, + "@polkadot/types-known": { + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.34.1.tgz", + "integrity": "sha512-H9V8u9cqbKjxU/dxEyLl7kJwoBImXpRskQ5+X0fq3BH7g1nQ6jrIg/buRPpbc3GxKivdFYUZWshPY9hbqE8y8A==", + "requires": { + "@babel/runtime": "^7.11.2", + "@polkadot/types": "1.34.1", + "@polkadot/util": "^3.4.1", + "bn.js": "^5.1.3" + } + }, + "@polkadot/util": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz", + "integrity": "sha512-CJo0wAzXR8vjAzs9mHDooZr5a3XRW8LlYWik8d/+bv1VDwCC/metSiBrYBOapFhYUjlS5IYIw5bhWS5dnpkXvQ==", + "requires": { + "@babel/runtime": "^7.11.2", + "@types/bn.js": "^4.11.6", + "bn.js": "^5.1.3", + "camelcase": "^5.3.1", + "chalk": "^4.1.0", + "ip-regex": "^4.1.0" + } + } + } + }, + "@polkadot/api-contract": { + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/api-contract/-/api-contract-1.34.1.tgz", + "integrity": "sha512-oXh7An6E9wdbczXQhw+TfIkoKLQr4t0j3OwxubrhS5Qn6f99xGoAkk0BIKjsHPGIbMHEJoywmmLrDUAeTxExgg==", + "requires": { + "@babel/runtime": "^7.11.2", + "@polkadot/api": "1.34.1", + "@polkadot/rpc-core": "1.34.1", + "@polkadot/types": "1.34.1", + "@polkadot/util": "^3.4.1", + "bn.js": "^5.1.3", + "rxjs": "^6.6.3" + }, + "dependencies": { + "@polkadot/api": { + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/api/-/api-1.34.1.tgz", + "integrity": "sha512-3gCibNRchH+XbEdULS1bwiV1RgarZW1PDw1Y1mAQBVqPrUpkYqntp1D52SQOpAbRzldkwk296Sj+mx9/IeDRXA==", + "requires": { + "@babel/runtime": "^7.11.2", + "@polkadot/api-derive": "1.34.1", + "@polkadot/keyring": "^3.4.1", + "@polkadot/metadata": "1.34.1", + "@polkadot/rpc-core": "1.34.1", + "@polkadot/rpc-provider": "1.34.1", + "@polkadot/types": "1.34.1", + "@polkadot/types-known": "1.34.1", + "@polkadot/util": "^3.4.1", + "@polkadot/util-crypto": "^3.4.1", + "bn.js": "^5.1.3", + "eventemitter3": "^4.0.7", + "rxjs": "^6.6.3" + } + }, + "@polkadot/api-derive": { + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/api-derive/-/api-derive-1.34.1.tgz", + "integrity": "sha512-LMlCkNJRp29MwKa36crYuY6cZpnkHCFrPCv9dmJEuDbMqrK+EAhXM9/6sTDYJ4uKNhyetJKe9rXslkXdI6pidA==", + "requires": { + "@babel/runtime": "^7.11.2", + "@polkadot/api": "1.34.1", + "@polkadot/rpc-core": "1.34.1", + "@polkadot/rpc-provider": "1.34.1", + "@polkadot/types": "1.34.1", + "@polkadot/util": "^3.4.1", + "@polkadot/util-crypto": "^3.4.1", + "bn.js": "^5.1.3", + "memoizee": "^0.4.14", + "rxjs": "^6.6.3" + } + }, + "@polkadot/metadata": { + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.34.1.tgz", + "integrity": "sha512-uoaOhNHjECDaLBYvGRaLvF0mhZBFmsV3oikYDP4sZx3a5oD0xYsyXtr5bFPQDImwPFASP8/ltrMVqcYTX42xFg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.31.2", - "@polkadot/types-known": "1.31.2", + "@polkadot/types": "1.34.1", + "@polkadot/types-known": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "bn.js": "^5.1.3" } }, + "@polkadot/rpc-core": { + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-core/-/rpc-core-1.34.1.tgz", + "integrity": "sha512-BVQDyBEkbRe5b/u8p9UPpTCj0sDZ32sTmPEP43Klc4s9+oHtiNvOFYvkjK5oyW9dlcOwXi8HpLsQxGAeMtM7Tw==", + "requires": { + "@babel/runtime": "^7.11.2", + "@polkadot/metadata": "1.34.1", + "@polkadot/rpc-provider": "1.34.1", + "@polkadot/types": "1.34.1", + "@polkadot/util": "^3.4.1", + "memoizee": "^0.4.14", + "rxjs": "^6.6.3" + } + }, + "@polkadot/rpc-provider": { + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-provider/-/rpc-provider-1.34.1.tgz", + "integrity": "sha512-bebeis9mB4LS9Spk1WSHoadZHsyHmK4gyyC6uKSLZxHZmnopWna6zWnOBIrYHRz7qDHSZC5eNTseuU8NJXtscA==", + "requires": { + "@babel/runtime": "^7.11.2", + "@polkadot/metadata": "1.34.1", + "@polkadot/types": "1.34.1", + "@polkadot/util": "^3.4.1", + "@polkadot/util-crypto": "^3.4.1", + "@polkadot/x-fetch": "^0.3.2", + "@polkadot/x-ws": "^0.3.2", + "bn.js": "^5.1.3", + "eventemitter3": "^4.0.7" + } + }, "@polkadot/types": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.31.2.tgz", - "integrity": "sha512-eJsWdMzBlkYYrowR7tl9LYvGW3Za05esDQPxPxc1z2kkwzU2IoX2qijhUb6J9ViESY/h0jWFyEbV/1mBn4uupg==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.34.1.tgz", + "integrity": "sha512-jPwix2y+ZXKYB4ghODXlqYmcI3Tnsl3iO3xIkiGsZhhs9PdrKibcNeAv4LUiRpPuGRnAM+mrlPrBbCuzguKSGg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/metadata": "1.31.2", + "@polkadot/metadata": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "@types/bn.js": "^4.11.6", "bn.js": "^5.1.3", "memoizee": "^0.4.14", - "rxjs": "^6.6.2" + "rxjs": "^6.6.3" } }, "@polkadot/types-known": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.31.2.tgz", - "integrity": "sha512-sA9IEwYNCsN+Z4eZklxOluJA5OBN2eGNvLz0uUQ6TFvqbi9Z8Mba+h+RZU1iFO6+yq2U7ECvdWzET6RN7zv+oQ==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.34.1.tgz", + "integrity": "sha512-H9V8u9cqbKjxU/dxEyLl7kJwoBImXpRskQ5+X0fq3BH7g1nQ6jrIg/buRPpbc3GxKivdFYUZWshPY9hbqE8y8A==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.31.2", + "@polkadot/types": "1.34.1", "@polkadot/util": "^3.4.1", "bn.js": "^5.1.3" } @@ -3990,57 +4125,57 @@ } }, "@polkadot/api-derive": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/api-derive/-/api-derive-1.31.2.tgz", - "integrity": "sha512-j33elEBZpY7/ucsBRYdUxeWHID8vlvPKm7k9dWgaH8txYuzms0SFfkMHyECgo15SL+RTNhu/VxzSRWryk6dvTA==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/api-derive/-/api-derive-1.34.1.tgz", + "integrity": "sha512-LMlCkNJRp29MwKa36crYuY6cZpnkHCFrPCv9dmJEuDbMqrK+EAhXM9/6sTDYJ4uKNhyetJKe9rXslkXdI6pidA==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/api": "1.31.2", - "@polkadot/rpc-core": "1.31.2", - "@polkadot/rpc-provider": "1.31.2", - "@polkadot/types": "1.31.2", + "@polkadot/api": "1.34.1", + "@polkadot/rpc-core": "1.34.1", + "@polkadot/rpc-provider": "1.34.1", + "@polkadot/types": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "bn.js": "^5.1.3", "memoizee": "^0.4.14", - "rxjs": "^6.6.2" + "rxjs": "^6.6.3" }, "dependencies": { "@polkadot/metadata": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.31.2.tgz", - "integrity": "sha512-UAcZLxh6QFwhF2Ccmax6LUYa99NntBZrAe8oUN92UJlHbtAutd5sq322P+liG2EHfyhUZs5T5v8jLD79pMTjdA==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.34.1.tgz", + "integrity": "sha512-uoaOhNHjECDaLBYvGRaLvF0mhZBFmsV3oikYDP4sZx3a5oD0xYsyXtr5bFPQDImwPFASP8/ltrMVqcYTX42xFg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.31.2", - "@polkadot/types-known": "1.31.2", + "@polkadot/types": "1.34.1", + "@polkadot/types-known": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "bn.js": "^5.1.3" } }, "@polkadot/types": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.31.2.tgz", - "integrity": "sha512-eJsWdMzBlkYYrowR7tl9LYvGW3Za05esDQPxPxc1z2kkwzU2IoX2qijhUb6J9ViESY/h0jWFyEbV/1mBn4uupg==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.34.1.tgz", + "integrity": "sha512-jPwix2y+ZXKYB4ghODXlqYmcI3Tnsl3iO3xIkiGsZhhs9PdrKibcNeAv4LUiRpPuGRnAM+mrlPrBbCuzguKSGg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/metadata": "1.31.2", + "@polkadot/metadata": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "@types/bn.js": "^4.11.6", "bn.js": "^5.1.3", "memoizee": "^0.4.14", - "rxjs": "^6.6.2" + "rxjs": "^6.6.3" } }, "@polkadot/types-known": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.31.2.tgz", - "integrity": "sha512-sA9IEwYNCsN+Z4eZklxOluJA5OBN2eGNvLz0uUQ6TFvqbi9Z8Mba+h+RZU1iFO6+yq2U7ECvdWzET6RN7zv+oQ==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.34.1.tgz", + "integrity": "sha512-H9V8u9cqbKjxU/dxEyLl7kJwoBImXpRskQ5+X0fq3BH7g1nQ6jrIg/buRPpbc3GxKivdFYUZWshPY9hbqE8y8A==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.31.2", + "@polkadot/types": "1.34.1", "@polkadot/util": "^3.4.1", "bn.js": "^5.1.3" } @@ -4167,13 +4302,13 @@ } }, "@polkadot/metadata": { - "version": "1.32.1", - "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.32.1.tgz", - "integrity": "sha512-0naYURBGYOMKF+z7RxOtIfhwziqIZ3GgXzYDRDra6goq72c4uykwpMUjkrJ07N9KaKBZsHmkn2k3v7pP5aqlzg==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.34.1.tgz", + "integrity": "sha512-uoaOhNHjECDaLBYvGRaLvF0mhZBFmsV3oikYDP4sZx3a5oD0xYsyXtr5bFPQDImwPFASP8/ltrMVqcYTX42xFg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.32.1", - "@polkadot/types-known": "1.32.1", + "@polkadot/types": "1.34.1", + "@polkadot/types-known": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "bn.js": "^5.1.3" @@ -4195,54 +4330,54 @@ } }, "@polkadot/rpc-core": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/rpc-core/-/rpc-core-1.31.2.tgz", - "integrity": "sha512-amFN0UtxB94TnXVuL9oBSQDFheCrxUN6C/lmVlOBqnWj6ZA1RDAuPPJBNIjhSxNlGmJxS2yIexaCVKgF8kS8Cg==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-core/-/rpc-core-1.34.1.tgz", + "integrity": "sha512-BVQDyBEkbRe5b/u8p9UPpTCj0sDZ32sTmPEP43Klc4s9+oHtiNvOFYvkjK5oyW9dlcOwXi8HpLsQxGAeMtM7Tw==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/metadata": "1.31.2", - "@polkadot/rpc-provider": "1.31.2", - "@polkadot/types": "1.31.2", + "@polkadot/metadata": "1.34.1", + "@polkadot/rpc-provider": "1.34.1", + "@polkadot/types": "1.34.1", "@polkadot/util": "^3.4.1", "memoizee": "^0.4.14", - "rxjs": "^6.6.2" + "rxjs": "^6.6.3" }, "dependencies": { "@polkadot/metadata": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.31.2.tgz", - "integrity": "sha512-UAcZLxh6QFwhF2Ccmax6LUYa99NntBZrAe8oUN92UJlHbtAutd5sq322P+liG2EHfyhUZs5T5v8jLD79pMTjdA==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.34.1.tgz", + "integrity": "sha512-uoaOhNHjECDaLBYvGRaLvF0mhZBFmsV3oikYDP4sZx3a5oD0xYsyXtr5bFPQDImwPFASP8/ltrMVqcYTX42xFg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.31.2", - "@polkadot/types-known": "1.31.2", + "@polkadot/types": "1.34.1", + "@polkadot/types-known": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "bn.js": "^5.1.3" } }, "@polkadot/types": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.31.2.tgz", - "integrity": "sha512-eJsWdMzBlkYYrowR7tl9LYvGW3Za05esDQPxPxc1z2kkwzU2IoX2qijhUb6J9ViESY/h0jWFyEbV/1mBn4uupg==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.34.1.tgz", + "integrity": "sha512-jPwix2y+ZXKYB4ghODXlqYmcI3Tnsl3iO3xIkiGsZhhs9PdrKibcNeAv4LUiRpPuGRnAM+mrlPrBbCuzguKSGg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/metadata": "1.31.2", + "@polkadot/metadata": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "@types/bn.js": "^4.11.6", "bn.js": "^5.1.3", "memoizee": "^0.4.14", - "rxjs": "^6.6.2" + "rxjs": "^6.6.3" } }, "@polkadot/types-known": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.31.2.tgz", - "integrity": "sha512-sA9IEwYNCsN+Z4eZklxOluJA5OBN2eGNvLz0uUQ6TFvqbi9Z8Mba+h+RZU1iFO6+yq2U7ECvdWzET6RN7zv+oQ==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.34.1.tgz", + "integrity": "sha512-H9V8u9cqbKjxU/dxEyLl7kJwoBImXpRskQ5+X0fq3BH7g1nQ6jrIg/buRPpbc3GxKivdFYUZWshPY9hbqE8y8A==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.31.2", + "@polkadot/types": "1.34.1", "@polkadot/util": "^3.4.1", "bn.js": "^5.1.3" } @@ -4263,56 +4398,56 @@ } }, "@polkadot/rpc-provider": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/rpc-provider/-/rpc-provider-1.31.2.tgz", - "integrity": "sha512-vqS1lsk/BBGSuklGKJhJxduKXOyXjc/kZzPWmmH8B92Zh59LqlzoJ8a4gQIjDr0CFjeJZbaaL1yRhE6qwaEe2A==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-provider/-/rpc-provider-1.34.1.tgz", + "integrity": "sha512-bebeis9mB4LS9Spk1WSHoadZHsyHmK4gyyC6uKSLZxHZmnopWna6zWnOBIrYHRz7qDHSZC5eNTseuU8NJXtscA==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/metadata": "1.31.2", - "@polkadot/types": "1.31.2", + "@polkadot/metadata": "1.34.1", + "@polkadot/types": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", + "@polkadot/x-fetch": "^0.3.2", + "@polkadot/x-ws": "^0.3.2", "bn.js": "^5.1.3", - "eventemitter3": "^4.0.6", - "isomorphic-fetch": "^2.2.1", - "websocket": "^1.0.31" + "eventemitter3": "^4.0.7" }, "dependencies": { "@polkadot/metadata": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.31.2.tgz", - "integrity": "sha512-UAcZLxh6QFwhF2Ccmax6LUYa99NntBZrAe8oUN92UJlHbtAutd5sq322P+liG2EHfyhUZs5T5v8jLD79pMTjdA==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.34.1.tgz", + "integrity": "sha512-uoaOhNHjECDaLBYvGRaLvF0mhZBFmsV3oikYDP4sZx3a5oD0xYsyXtr5bFPQDImwPFASP8/ltrMVqcYTX42xFg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.31.2", - "@polkadot/types-known": "1.31.2", + "@polkadot/types": "1.34.1", + "@polkadot/types-known": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "bn.js": "^5.1.3" } }, "@polkadot/types": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.31.2.tgz", - "integrity": "sha512-eJsWdMzBlkYYrowR7tl9LYvGW3Za05esDQPxPxc1z2kkwzU2IoX2qijhUb6J9ViESY/h0jWFyEbV/1mBn4uupg==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.34.1.tgz", + "integrity": "sha512-jPwix2y+ZXKYB4ghODXlqYmcI3Tnsl3iO3xIkiGsZhhs9PdrKibcNeAv4LUiRpPuGRnAM+mrlPrBbCuzguKSGg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/metadata": "1.31.2", + "@polkadot/metadata": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "@types/bn.js": "^4.11.6", "bn.js": "^5.1.3", "memoizee": "^0.4.14", - "rxjs": "^6.6.2" + "rxjs": "^6.6.3" } }, "@polkadot/types-known": { - "version": "1.31.2", - "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.31.2.tgz", - "integrity": "sha512-sA9IEwYNCsN+Z4eZklxOluJA5OBN2eGNvLz0uUQ6TFvqbi9Z8Mba+h+RZU1iFO6+yq2U7ECvdWzET6RN7zv+oQ==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.34.1.tgz", + "integrity": "sha512-H9V8u9cqbKjxU/dxEyLl7kJwoBImXpRskQ5+X0fq3BH7g1nQ6jrIg/buRPpbc3GxKivdFYUZWshPY9hbqE8y8A==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.31.2", + "@polkadot/types": "1.34.1", "@polkadot/util": "^3.4.1", "bn.js": "^5.1.3" } @@ -4342,18 +4477,18 @@ } }, "@polkadot/types": { - "version": "1.32.1", - "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.32.1.tgz", - "integrity": "sha512-n+77dHE5J3RqmnbOwMdAeQg5yv68/2qZ7JeBw/KjYtSnJoA2pbW7yL01zSkIUCJcaTb/yuSQz9SK7Cz9QQ6MOw==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.34.1.tgz", + "integrity": "sha512-jPwix2y+ZXKYB4ghODXlqYmcI3Tnsl3iO3xIkiGsZhhs9PdrKibcNeAv4LUiRpPuGRnAM+mrlPrBbCuzguKSGg==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/metadata": "1.32.1", + "@polkadot/metadata": "1.34.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "@types/bn.js": "^4.11.6", "bn.js": "^5.1.3", "memoizee": "^0.4.14", - "rxjs": "^6.6.2" + "rxjs": "^6.6.3" }, "dependencies": { "@polkadot/util": { @@ -4372,12 +4507,12 @@ } }, "@polkadot/types-known": { - "version": "1.32.1", - "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.32.1.tgz", - "integrity": "sha512-Vv8m5w+v2nKjYIWEvjohW2xZd+v98bgKwzyl+Y7ssbnxMAYZQYkuzR8IDfUXyzcL+p9VF+YFExVnzCakMm756Q==", + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.34.1.tgz", + "integrity": "sha512-H9V8u9cqbKjxU/dxEyLl7kJwoBImXpRskQ5+X0fq3BH7g1nQ6jrIg/buRPpbc3GxKivdFYUZWshPY9hbqE8y8A==", "requires": { "@babel/runtime": "^7.11.2", - "@polkadot/types": "1.32.1", + "@polkadot/types": "1.34.1", "@polkadot/util": "^3.4.1", "bn.js": "^5.1.3" }, @@ -4398,13 +4533,13 @@ } }, "@polkadot/util": { - "version": "2.18.1", - "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-2.18.1.tgz", - "integrity": "sha512-0KAojJMR5KDaaobIyvHVuW9vBP5LG3S0vpRSovB4UPlGDok3ETJSm5lMhA0t2KM8C4gXGBakCotFVGSOvWGgjA==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz", + "integrity": "sha512-CJo0wAzXR8vjAzs9mHDooZr5a3XRW8LlYWik8d/+bv1VDwCC/metSiBrYBOapFhYUjlS5IYIw5bhWS5dnpkXvQ==", "requires": { - "@babel/runtime": "^7.10.4", + "@babel/runtime": "^7.11.2", "@types/bn.js": "^4.11.6", - "bn.js": "^5.1.2", + "bn.js": "^5.1.3", "camelcase": "^5.3.1", "chalk": "^4.1.0", "ip-regex": "^4.1.0" @@ -4450,6 +4585,33 @@ "resolved": "https://registry.npmjs.org/@polkadot/wasm-crypto/-/wasm-crypto-1.4.1.tgz", "integrity": "sha512-GPBCh8YvQmA5bobI4rqRkUhrEHkEWU1+lcJVPbZYsa7jiHFaZpzCLrGQfiqW/vtbU1aBS2wmJ0x1nlt33B9QqQ==" }, + "@polkadot/x-fetch": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@polkadot/x-fetch/-/x-fetch-0.3.2.tgz", + "integrity": "sha512-lk9M8ql/kBBqiZ8KOWj7LFK7P9OxDgVn2fZPNELJzQbfFZwFF8umBPDIWlQIK7wTnlRsQlzOuf6MGEyMK5p42w==", + "requires": { + "@babel/runtime": "^7.11.2", + "@types/node-fetch": "^2.5.7", + "node-fetch": "^2.6.1" + }, + "dependencies": { + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + } + } + }, + "@polkadot/x-ws": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@polkadot/x-ws/-/x-ws-0.3.2.tgz", + "integrity": "sha512-1aiG11Py8sgzJsz19melMzvBOn5zeMmfjCPoMryX4//063E0mcfnkujg4O6pTMygxJdFGAV1INB9wvMU9Dg9Wg==", + "requires": { + "@babel/runtime": "^7.11.2", + "@types/websocket": "^1.0.1", + "websocket": "^1.0.32" + } + }, "@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", @@ -4667,6 +4829,27 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-14.6.4.tgz", "integrity": "sha512-Wk7nG1JSaMfMpoMJDKUsWYugliB2Vy55pdjLpmLixeyMi7HizW2I/9QoxsPCkXl3dO+ZOVqPumKaDUv5zJu2uQ==" }, + "@types/node-fetch": { + "version": "2.5.7", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.7.tgz", + "integrity": "sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==", + "requires": { + "@types/node": "*", + "form-data": "^3.0.0" + }, + "dependencies": { + "form-data": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz", + "integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, "@types/normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -4691,6 +4874,14 @@ "integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==", "dev": true }, + "@types/websocket": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/websocket/-/websocket-1.0.1.tgz", + "integrity": "sha512-f5WLMpezwVxCLm1xQe/kdPpQIOmL0TXYx2O15VYfYzc7hTIdxiOoOvez+McSIw3b7z/1zGovew9YSL7+h4h7/Q==", + "requires": { + "@types/node": "*" + } + }, "@types/yargs": { "version": "15.0.5", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.5.tgz", @@ -5951,8 +6142,7 @@ "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", - "dev": true + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, "at-least-node": { "version": "1.0.0", @@ -7364,7 +7554,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -9081,8 +9270,7 @@ "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", - "dev": true + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, "delegate": { "version": "3.2.0", @@ -9700,6 +9888,7 @@ "version": "0.1.13", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", + "dev": true, "requires": { "iconv-lite": "^0.6.2" } @@ -12954,6 +13143,7 @@ "version": "0.6.2", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.2.tgz", "integrity": "sha512-2y91h5OpQlolefMPmUlivelittSWy0rP+oYVpn6A7GwVHNE8AWzoYOBNmlwks3LobaJxgHCYZAnyNo2GgpNRNQ==", + "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3.0.0" } @@ -13717,7 +13907,8 @@ "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", + "dev": true }, "is-string": { "version": "1.0.5", @@ -13808,15 +13999,6 @@ "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", "dev": true - }, - "isomorphic-fetch": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", - "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", - "requires": { - "node-fetch": "^1.0.1", - "whatwg-fetch": ">=0.10.0" - } }, "isstream": { "version": "0.1.2", @@ -15870,14 +16052,12 @@ "mime-db": { "version": "1.44.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", - "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==", - "dev": true + "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==" }, "mime-types": { "version": "2.1.27", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", - "dev": true, "requires": { "mime-db": "1.44.0" } @@ -16658,15 +16838,6 @@ "dev": true, "requires": { "lower-case": "^1.1.1" - } - }, - "node-fetch": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", - "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", - "requires": { - "encoding": "^0.1.11", - "is-stream": "^1.0.1" } }, "node-fetch-npm": { @@ -19728,7 +19899,8 @@ "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true }, "sane": { "version": "4.1.0", @@ -23597,11 +23769,6 @@ } } } - }, - "whatwg-fetch": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.4.1.tgz", - "integrity": "sha512-sofZVzE1wKwO+EYPbWfiwzaKovWiZXf4coEzjGP9b2GBVgQRLQUZ2QcuPpQExGDAW5GItpEm6Tl4OU5mywnAoQ==" }, "whatwg-mimetype": { "version": "2.3.0", --- a/tests/package.json +++ b/tests/package.json @@ -23,9 +23,10 @@ "license": "Apache 2.0", "homepage": "", "dependencies": { - "@polkadot/api": "^1.31.2", - "@polkadot/types": "^1.31.2", - "@polkadot/util": "^2.18.1", + "@polkadot/api": "^1.34.1", + "@polkadot/api-contract": "^1.34.1", + "@polkadot/types": "^1.34.1", + "@polkadot/util": "^3.4.1", "@types/bn.js": "^4.11.6", "chai-as-promised": "^7.1.1" }, --- /dev/null +++ b/tests/src/accounts.ts @@ -0,0 +1,2 @@ +export const bobsPublicKey = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'; +export const alicesPublicKey = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; --- /dev/null +++ b/tests/src/deploy-flipper.test.ts @@ -0,0 +1,102 @@ +import { expect } from "chai"; +import usingApi from "./substrate/substrate-api"; +import promisifySubstrate from "./substrate/promisify-substrate"; +import fs from "fs"; +import privateKey from "./substrate/privateKey"; +import { compactAddLength, u8aToU8a } from '@polkadot/util'; +import { Hash, AccountId } from "@polkadot/types/interfaces"; +import { Abi, PromiseContract } from "@polkadot/api-contract"; +import { ISubmittableResult } from "@polkadot/types/types"; +import BN from "bn.js"; +import { alicesPublicKey } from "./accounts"; + +describe('Flipper', () => { + it(`Can deploy smart contract Flipper, instantiate it and call it's get and flip messages.`, async () => { + await usingApi(async api => { + const wasm = fs.readFileSync('./src/flipper/flipper.wasm'); + const contract = compactAddLength(u8aToU8a(wasm)); + + const metadata = JSON.parse(fs.readFileSync('./src/flipper/metadata.json').toString('utf-8')); + const abi = new Abi(api.registry as any, metadata); + + const alicesPrivateKey = privateKey('//Alice'); + + const contractHash = await promisifySubstrate(api, () => { + return new Promise(async (resolve, reject) => { + const unsubscribe = api.tx.contracts.putCode(contract).signAndSend(alicesPrivateKey, async result => { + if(!result.isInBlock){ + return; + } + + const record = result.findRecord('contracts', 'CodeStored'); + + if(record) { + (await unsubscribe)(); + resolve(record.event.data[0] as unknown as Hash); + } else { + reject('Failed to find contract hash in putCode transaction result.'); + } + }); + }) + })(); + + + const instanceAccountId = await promisifySubstrate(api, () => { + return new Promise((resolve, reject) => { + const args = abi.constructors[0](true); + const unsubscribe = api.tx.contracts.instantiate(1000000000000000n, 1000000000000n, contractHash, args) + .signAndSend(alicesPrivateKey, async (result:ISubmittableResult) => { + if(!result.isInBlock) { + return; + } + const record = result.findRecord('contracts', 'Instantiated'); + if(record) { + (await unsubscribe)(); + expect(alicesPublicKey).to.be.equal(record.event.data[0].toString()); + resolve(record.event.data[1] as AccountId); + } else { + reject('Failed to find instantiated event,'); + } + }); + }); + })(); + + const contractInstance = new PromiseContract(api, abi, instanceAccountId); + const getFlipValue = async () => { + return await promisifySubstrate(api, async () => { + const result = await contractInstance.call('rpc', 'get', 0, new BN('1000000000000')) + .send(alicesPublicKey); + if(!result.isSuccess) { + throw 'Failed to get flipper value'; + } + return result.output && result.output.valueOf && result.output.valueOf(); + })(); + } + + const initialGetResponse = await getFlipValue(); + expect(initialGetResponse).to.be.true; + + await promisifySubstrate(api, async () => { + return new Promise(async (resolve, reject) => { + api.tx.contracts.call(contractInstance.address.toString(), 0, 1000000000000n, contractInstance.getMessage('flip').fn()) + .signAndSend(alicesPrivateKey, async result => { + if(!result.isInBlock) { + return; + } + + if(result.findRecord('system', 'ExtrinsicSuccess')) { + resolve(); + } + else { + reject('Failed to flip value.'); + } + }) + }); + })(); + + const afterFlipGetResponse = await getFlipValue(); + + expect(afterFlipGetResponse).to.be.false; + }); + }); +}); --- /dev/null +++ b/tests/src/flipper/metadata.json @@ -0,0 +1,204 @@ +{ + "registry": { + "strings": [ + "Storage", + "flipper", + "__ink_private", + "__ink_storage", + "value", + "Value", + "ink_core", + "storage", + "cell", + "SyncCell", + "sync_cell", + "Key", + "ink_primitives", + "new", + "init_value", + "bool", + "default", + "flip", + "get" + ], + "types": [ + { + "id": { + "custom.name": 1, + "custom.namespace": [ + 2, + 2, + 3, + 4 + ], + "custom.params": [] + }, + "def": { + "struct.fields": [ + { + "name": 5, + "type": 2 + } + ] + } + }, + { + "id": { + "custom.name": 6, + "custom.namespace": [ + 7, + 8, + 5 + ], + "custom.params": [ + 3 + ] + }, + "def": { + "struct.fields": [ + { + "name": 9, + "type": 4 + } + ] + } + }, + { + "id": "bool", + "def": "builtin" + }, + { + "id": { + "custom.name": 10, + "custom.namespace": [ + 7, + 8, + 9, + 11 + ], + "custom.params": [ + 3 + ] + }, + "def": { + "struct.fields": [ + { + "name": 9, + "type": 5 + } + ] + } + }, + { + "id": { + "custom.name": 12, + "custom.namespace": [ + 13 + ], + "custom.params": [] + }, + "def": { + "tuple_struct.types": [ + 6 + ] + } + }, + { + "id": { + "array.len": 32, + "array.type": 7 + }, + "def": "builtin" + }, + { + "id": "u8", + "def": "builtin" + } + ] + }, + "storage": { + "struct.type": 1, + "struct.fields": [ + { + "name": 5, + "layout": { + "struct.type": 2, + "struct.fields": [ + { + "name": 9, + "layout": { + "range.offset": "0x0000000000000000000000000000000000000000000000000000000000000000", + "range.len": 1, + "range.elem_type": 3 + } + } + ] + } + } + ] + }, + "contract": { + "name": 2, + "constructors": [ + { + "name": 14, + "selector": "[\"0x5E\",\"0xBD\",\"0x88\",\"0xD6\"]", + "args": [ + { + "name": 15, + "type": { + "ty": 3, + "display_name": [ + 16 + ] + } + } + ], + "docs": [ + "Constructor that initializes the `bool` value to the given `init_value`." + ] + }, + { + "name": 17, + "selector": "[\"0x02\",\"0x22\",\"0xFF\",\"0x18\"]", + "args": [], + "docs": [ + "Constructor that initializes the `bool` value to `false`.", + "", + "Constructors can delegate to other constructors." + ] + } + ], + "messages": [ + { + "name": 18, + "selector": "[\"0x8C\",\"0x97\",\"0xDB\",\"0x39\"]", + "mutates": true, + "args": [], + "return_type": null, + "docs": [ + "A message that can be called on instantiated contracts.", + "This one flips the value of the stored `bool` from `true`", + "to `false` and vice versa." + ] + }, + { + "name": 19, + "selector": "[\"0x25\",\"0x44\",\"0x4A\",\"0xFE\"]", + "mutates": false, + "args": [], + "return_type": { + "ty": 3, + "display_name": [ + 16 + ] + }, + "docs": [ + "Simply returns the current value of our `bool`." + ] + } + ], + "events": [], + "docs": [] + } +} \ No newline at end of file --- /dev/null +++ b/tests/src/substrate/privateKey.ts @@ -0,0 +1,7 @@ +import { Keyring } from "@polkadot/api"; + +export default function privateKey(account: string) { + const keyring = new Keyring({ type: 'sr25519' }); + + return keyring.addFromUri(account); +} \ No newline at end of file --- a/tests/src/transfer.test.ts +++ b/tests/src/transfer.test.ts @@ -5,6 +5,8 @@ import usingApi from "./substrate/substrate-api"; import promisifySubstrate from "./substrate/promisify-substrate"; import waitNewBlocks from "./substrate/wait-new-blocks"; +import { alicesPublicKey, bobsPublicKey } from "./accounts"; +import privateKey from "./substrate/privateKey"; async function getBalance(api: ApiPromise, accounts: string[]): Promise { const balance = promisifySubstrate(api, (accounts: string[]) => api.query.system.account.multi(accounts)); @@ -14,18 +16,14 @@ describe('Transfer', () => { it('Balance transfers', async () => { - const bobsPublicKey = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'; - const alicesPublicKey = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; await usingApi(async api => { const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]); - const keyring = new Keyring({ type: 'sr25519' }); - - const alicePrivateKey = keyring.addFromUri('//Alice'); + const alicePrivateKey = privateKey('//Alice'); const transfer = api.tx.balances.transfer(bobsPublicKey, 1n); - const hash = await transfer.signAndSend(alicePrivateKey); + await promisifySubstrate(api, () => transfer.signAndSend(alicePrivateKey))(); await waitNewBlocks(api); -- gitstuff