difftreelog
CORE-300 Fix PR
in: master
12 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -68,7 +68,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
- "getrandom 0.2.5",
+ "getrandom 0.2.6",
"once_cell",
"version_check",
]
@@ -306,9 +306,9 @@
[[package]]
name = "async-trait"
-version = "0.1.52"
+version = "0.1.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3"
+checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600"
dependencies = [
"proc-macro2",
"quote",
@@ -392,7 +392,7 @@
checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1"
dependencies = [
"futures-core",
- "getrandom 0.2.5",
+ "getrandom 0.2.6",
"instant",
"pin-project-lite 0.2.8",
"rand 0.8.5",
@@ -440,9 +440,9 @@
[[package]]
name = "base64ct"
-version = "1.4.1"
+version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "71acf5509fc522cce1b100ac0121c635129bfd4d91cdf036bcc9b9935f97ccf5"
+checksum = "dea908e7347a8c64e378c17e30ef880ad73e3b4498346b055c2c00ea342f3179"
[[package]]
name = "beef"
@@ -990,7 +990,7 @@
dependencies = [
"camino",
"cargo-platform",
- "semver 1.0.6",
+ "semver 1.0.7",
"serde",
"serde_json",
]
@@ -2753,7 +2753,7 @@
[[package]]
name = "fp-evm-mapping"
version = "0.1.0"
-source = "git+https://github.com/uniquenetwork/frontier.git?branch=feature/300#8718bfde84a370f5a6e7642b216dd913ca33db5c"
+source = "git+https://github.com/uniquenetwork/frontier.git?branch=feature/300#28e11d419537bde416bc84b1604b4d0f3da879e0"
dependencies = [
"frame-support",
"sp-core",
@@ -3243,9 +3243,9 @@
[[package]]
name = "getrandom"
-version = "0.2.5"
+version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
+checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
dependencies = [
"cfg-if 1.0.0",
"libc",
@@ -3688,9 +3688,9 @@
[[package]]
name = "indexmap"
-version = "1.8.0"
+version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
+checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
dependencies = [
"autocfg",
"hashbrown 0.11.2",
@@ -6181,6 +6181,7 @@
version = "0.1.0"
dependencies = [
"fp-evm",
+ "fp-evm-mapping",
"frame-support",
"frame-system",
"pallet-ethereum",
@@ -6807,6 +6808,7 @@
"ethereum",
"evm-coder",
"fp-evm",
+ "fp-evm-mapping",
"frame-benchmarking",
"frame-support",
"frame-system",
@@ -7117,9 +7119,9 @@
[[package]]
name = "paste"
-version = "1.0.6"
+version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5"
+checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc"
[[package]]
name = "pbkdf2"
@@ -8803,9 +8805,9 @@
[[package]]
name = "quote"
-version = "1.0.16"
+version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57"
+checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58"
dependencies = [
"proc-macro2",
]
@@ -8876,7 +8878,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
- "getrandom 0.2.5",
+ "getrandom 0.2.6",
]
[[package]]
@@ -8940,9 +8942,9 @@
[[package]]
name = "redox_syscall"
-version = "0.2.11"
+version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c"
+checksum = "8ae183fc1b06c149f0c1793e1eb447c8b04bfe46d48e9e48bfb8d2d7ed64ecf0"
dependencies = [
"bitflags",
]
@@ -8953,7 +8955,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7776223e2696f1aa4c6b0170e83212f47296a00424305117d013dfe86fb0fe55"
dependencies = [
- "getrandom 0.2.5",
+ "getrandom 0.2.6",
"redox_syscall",
"thiserror",
]
@@ -9267,7 +9269,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
- "semver 1.0.6",
+ "semver 1.0.7",
]
[[package]]
@@ -10546,9 +10548,9 @@
[[package]]
name = "semver"
-version = "1.0.6"
+version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4a3381e03edd24287172047536f20cabde766e2cd3e65e6b00fb3af51c4f38d"
+checksum = "d65bd28f48be7196d222d95b9243287f48d27aca604e08497513019ff0502cc4"
dependencies = [
"serde",
]
@@ -11815,9 +11817,9 @@
[[package]]
name = "syn"
-version = "1.0.89"
+version = "1.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54"
+checksum = "704df27628939572cd88d33f171cd6f896f4eaca85252c6e0a72d8d8287ee86f"
dependencies = [
"proc-macro2",
"quote",
@@ -12196,7 +12198,7 @@
"chrono",
"lazy_static",
"matchers",
- "parking_lot 0.10.2",
+ "parking_lot 0.11.2",
"regex",
"serde",
"serde_json",
@@ -12414,7 +12416,7 @@
[[package]]
name = "unique-node"
-version = "0.9.17"
+version = "0.9.18"
dependencies = [
"clap",
"cumulus-client-cli",
@@ -12628,6 +12630,7 @@
"frame-support",
"frame-system",
"pallet-common",
+ "pallet-evm",
"parity-scale-codec",
"scale-info",
"sp-consensus-aura",
client/rpc/Cargo.tomldiffbeforeafterboth--- a/client/rpc/Cargo.toml
+++ b/client/rpc/Cargo.toml
@@ -19,4 +19,3 @@
sp-rpc = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
-frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -283,7 +283,7 @@
license = 'GPLv3'
name = 'unique-node'
repository = 'https://github.com/UniqueNetwork/unique-chain'
-version = '0.9.17'
+version = '0.9.18'
[[bin]]
name = 'unique-collator'
pallets/common/Cargo.tomldiffbeforeafterboth--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -21,7 +21,6 @@
pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
evm-coder = { default-features = false, path = '../../crates/evm-coder' }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
-frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
serde = { version = "1.0.130", default-features = false }
scale-info = { version = "2.0.1", default-features = false, features = [
"derive",
primitives/rpc/Cargo.tomldiffbeforeafterboth--- a/primitives/rpc/Cargo.toml
+++ b/primitives/rpc/Cargo.toml
@@ -14,7 +14,7 @@
sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
sp-api = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
-frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
[features]
default = ["std"]
runtime/common/Cargo.tomldiffbeforeafterboth--- a/runtime/common/Cargo.toml
+++ b/runtime/common/Cargo.toml
@@ -70,3 +70,6 @@
default-features = false
git = "https://github.com/uniquenetwork/frontier.git"
branch = "unique-polkadot-v0.9.18"
+
+[dependencies]
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
\ No newline at end of file
runtime/common/src/types.rsdiffbeforeafterboth--- a/runtime/common/src/types.rs
+++ b/runtime/common/src/types.rs
@@ -42,7 +42,7 @@
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub trait RuntimeInstance {
- type CrossAccountId: pallet_common::account::CrossAccountId<sp_runtime::AccountId32>
+ type CrossAccountId: pallet_evm::account::CrossAccountId<sp_runtime::AccountId32>
+ Send
+ Sync
+ 'static;
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -116,7 +116,7 @@
pub const RUNTIME_NAME: &str = "Opal";
-type CrossAccountId = frame_common::account::BasicCrossAccountId<Runtime>;
+type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;
impl RuntimeInstance for Runtime {
type CrossAccountId = self::CrossAccountId;
runtime/quartz/src/lib.rsdiffbeforeafterboth--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -116,7 +116,7 @@
pub const RUNTIME_NAME: &str = "Quartz";
-type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;
+type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;
impl RuntimeInstance for Runtime {
type CrossAccountId = self::CrossAccountId;
@@ -844,9 +844,6 @@
impl pallet_common::Config for Runtime {
type Event = Event;
- type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;
- type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;
- type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;
type Currency = Balances;
type CollectionCreationPrice = CollectionCreationPrice;
@@ -917,8 +914,6 @@
impl pallet_evm_transaction_payment::Config for Runtime {
type EvmSponsorshipHandler = EvmSponsorshipHandler;
type Currency = Balances;
- type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;
- type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;
}
impl pallet_charge_transaction::Config for Runtime {
runtime/unique/Cargo.tomldiffbeforeafterboth--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -401,7 +401,6 @@
fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
fp-self-contained = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
fp-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
-frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
################################################################################
# Build Dependencies
runtime/unique/src/lib.rsdiffbeforeafterboth--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -115,7 +115,7 @@
pub const RUNTIME_NAME: &str = "Unique";
-type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;
+type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;
impl RuntimeInstance for Runtime {
type CrossAccountId = self::CrossAccountId;
@@ -843,10 +843,6 @@
impl pallet_common::Config for Runtime {
type Event = Event;
- type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;
- type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;
- type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;
-
type Currency = Balances;
type CollectionCreationPrice = CollectionCreationPrice;
type TreasuryAccountId = TreasuryAccountId;
@@ -916,8 +912,6 @@
impl pallet_evm_transaction_payment::Config for Runtime {
type EvmSponsorshipHandler = EvmSponsorshipHandler;
type Currency = Balances;
- type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;
- type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;
}
impl pallet_charge_transaction::Config for Runtime {
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import privateKey from '../substrate/privateKey';18import {expect} from 'chai';19import {20 contractHelpers,21 createEthAccountWithBalance,22 transferBalanceToEth,23 deployFlipper,24 itWeb3,25 SponsoringMode,26 createEthAccount,27 collectionIdToAddress,28 GAS_ARGS,29 normalizeEvents,30} from './util/helpers';31import {32 createCollectionExpectSuccess,33 getCreateCollectionResult,34} from '../util/helpers';35import nonFungibleAbi from './nonFungibleAbi.json';36import {37 submitTransactionAsync,38} from '../substrate/substrate-api';39import getBalance from '../substrate/get-balance';40import {alicesPublicKey} from '../accounts';4142describe('Sponsoring EVM contracts', () => {43 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {44 const owner = await createEthAccountWithBalance(api, web3);45 const flipper = await deployFlipper(web3, owner);46 const helpers = contractHelpers(web3, owner);47 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;48 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});49 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;50 });5152 itWeb3('Sponsoring cannot be set by the address that did not deployed the contract', async ({api, web3}) => {53 const owner = await createEthAccountWithBalance(api, web3);54 const notOwner = await createEthAccountWithBalance(api, web3);55 const flipper = await deployFlipper(web3, owner);56 const helpers = contractHelpers(web3, owner);57 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;58 await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).send({from: notOwner})).to.rejected;59 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;60 });6162 itWeb3('In generous mode, non-allowlisted user transaction will be sponsored', async ({api, web3}) => {63 const alice = privateKey('//Alice');6465 const owner = await createEthAccountWithBalance(api, web3);66 const caller = await createEthAccountWithBalance(api, web3);6768 const flipper = await deployFlipper(web3, owner);6970 const helpers = contractHelpers(web3, owner);7172 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;73 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});74 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});75 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;7677 await transferBalanceToEth(api, alice, flipper.options.address);7879 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);80 expect(originalFlipperBalance).to.be.not.equal('0');8182 await flipper.methods.flip().send({from: caller});83 expect(await flipper.methods.getValue().call()).to.be.true;8485 // Balance should be taken from flipper instead of caller86 const balanceAfter = await web3.eth.getBalance(flipper.options.address);87 expect(+balanceAfter).to.be.lessThan(+originalFlipperBalance);88 });8990 itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({api, web3}) => {91 const alice = privateKey('//Alice');9293 const owner = await createEthAccountWithBalance(api, web3);94 const caller = createEthAccount(web3);9596 const flipper = await deployFlipper(web3, owner);9798 const helpers = contractHelpers(web3, owner);99 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});100 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});101102 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;103 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});104 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});105 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;106107 await transferBalanceToEth(api, alice, flipper.options.address);108109 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);110 expect(originalFlipperBalance).to.be.not.equal('0');111112 await flipper.methods.flip().send({from: caller});113 expect(await flipper.methods.getValue().call()).to.be.true;114115 // Balance should be taken from flipper instead of caller116 const balanceAfter = await web3.eth.getBalance(flipper.options.address);117 expect(+balanceAfter).to.be.lessThan(+originalFlipperBalance);118 });119120 itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({api, web3}) => {121 const alice = privateKey('//Alice');122123 const owner = await createEthAccountWithBalance(api, web3);124 const caller = createEthAccount(web3);125126 const flipper = await deployFlipper(web3, owner);127128 const helpers = contractHelpers(web3, owner);129130 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;131 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});132 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});133 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;134135 await transferBalanceToEth(api, alice, flipper.options.address);136137 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);138 expect(originalFlipperBalance).to.be.not.equal('0');139140 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/InvalidTransaction::Payment/);141 expect(await flipper.methods.getValue().call()).to.be.false;142143 // Balance should be taken from flipper instead of caller144 const balanceAfter = await web3.eth.getBalance(flipper.options.address);145 expect(+balanceAfter).to.be.equals(+originalFlipperBalance);146 });147148 itWeb3('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({api, web3}) => {149 const alice = privateKey('//Alice');150151 const owner = await createEthAccountWithBalance(api, web3);152 const caller = await createEthAccountWithBalance(api, web3);153 const originalCallerBalance = await web3.eth.getBalance(caller);154155 const flipper = await deployFlipper(web3, owner);156157 const helpers = contractHelpers(web3, owner);158 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});159 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});160161 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;162 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});163 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});164 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;165166 await transferBalanceToEth(api, alice, flipper.options.address);167168 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);169 expect(originalFlipperBalance).to.be.not.equal('0');170171 await flipper.methods.flip().send({from: caller});172 expect(await flipper.methods.getValue().call()).to.be.true;173174 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);175 });176177 itWeb3('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({api, web3}) => {178 const alice = privateKey('//Alice');179180 const owner = await createEthAccountWithBalance(api, web3);181 const caller = await createEthAccountWithBalance(api, web3);182 const originalCallerBalance = await web3.eth.getBalance(caller);183184 const flipper = await deployFlipper(web3, owner);185186 const helpers = contractHelpers(web3, owner);187 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});188 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});189190 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;191 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});192 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 10).send({from: owner});193 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;194195 await transferBalanceToEth(api, alice, flipper.options.address);196197 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);198 expect(originalFlipperBalance).to.be.not.equal('0');199200 await flipper.methods.flip().send({from: caller});201 expect(await flipper.methods.getValue().call()).to.be.true;202 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);203204 await flipper.methods.flip().send({from: caller});205 expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance);206 });207208 // TODO: Find a way to calculate default rate limit209 itWeb3('Default rate limit equals 7200', async ({api, web3}) => {210 const owner = await createEthAccountWithBalance(api, web3);211 const flipper = await deployFlipper(web3, owner);212 const helpers = contractHelpers(web3, owner);213 expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');214 });215216 itWeb3.only('Sponsoring evm address from substrate collection', async ({api, web3}) => {217 const owner = privateKey('//Alice');218 const userEth = createEthAccount(web3);219 const collectionId = await createCollectionExpectSuccess();220221 {222 const tx = api.tx.unique.setCollectionSponsor(collectionId, owner.address);223 const events = await submitTransactionAsync(owner, tx);224 const result = getCreateCollectionResult(events);225 expect(result.success).to.be.true;226 }227 {228 const tx = api.tx.unique.confirmSponsorship(collectionId);229 const events = await submitTransactionAsync(owner, tx);230 const result = getCreateCollectionResult(events);231 expect(result.success).to.be.true;232 }233234 const address = collectionIdToAddress(collectionId);235 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: userEth, ...GAS_ARGS});236237 { // This part should fail, because user not in access list and user have no money238 const nextTokenId = await contract.methods.nextTokenId().call();239 expect(nextTokenId).to.be.equal('1');240 await expect(contract.methods.mintWithTokenURI(241 userEth,242 nextTokenId,243 'Test URI',244 ).call({from: userEth})).to.be.rejectedWith(/PublicMintingNotAllowed/);245 }246247 {248 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');249 const events = await submitTransactionAsync(owner, tx);250 const result = getCreateCollectionResult(events);251 expect(result.success).to.be.true;252 }253 {254 const tx = api.tx.unique.addToAllowList(collectionId, {Ethereum: userEth});255 const events = await submitTransactionAsync(owner, tx);256 const result = getCreateCollectionResult(events);257 expect(result.success).to.be.true;258 }259 {260 const tx = api.tx.unique.setMintPermission(collectionId, true);261 const events = await submitTransactionAsync(owner, tx);262 const result = getCreateCollectionResult(events);263 expect(result.success).to.be.true;264 }265266 const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);267268 {269 const nextTokenId = await contract.methods.nextTokenId().call();270 expect(nextTokenId).to.be.equal('1');271 const result = await contract.methods.mintWithTokenURI(272 userEth,273 nextTokenId,274 'Test URI',275 ).send({from: userEth});276 const events = normalizeEvents(result.events);277278 expect(events).to.be.deep.equal([279 {280 address,281 event: 'Transfer',282 args: {283 from: '0x0000000000000000000000000000000000000000',284 to: userEth,285 tokenId: nextTokenId,286 },287 },288 ]);289290 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');291 }292293 const [alicesBalanceAfter] = await getBalance(api, [alicesPublicKey]);294 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;295 });296});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import privateKey from '../substrate/privateKey';18import {expect} from 'chai';19import {20 contractHelpers,21 createEthAccountWithBalance,22 transferBalanceToEth,23 deployFlipper,24 itWeb3,25 SponsoringMode,26 createEthAccount,27 collectionIdToAddress,28 GAS_ARGS,29 normalizeEvents,30} from './util/helpers';31import {32 createCollectionExpectSuccess,33 getCreateCollectionResult,34} from '../util/helpers';35import nonFungibleAbi from './nonFungibleAbi.json';36import {37 submitTransactionAsync,38} from '../substrate/substrate-api';39import getBalance from '../substrate/get-balance';40import {alicesPublicKey} from '../accounts';4142describe('Sponsoring EVM contracts', () => {43 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {44 const owner = await createEthAccountWithBalance(api, web3);45 const flipper = await deployFlipper(web3, owner);46 const helpers = contractHelpers(web3, owner);47 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;48 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});49 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;50 });5152 itWeb3('Sponsoring cannot be set by the address that did not deployed the contract', async ({api, web3}) => {53 const owner = await createEthAccountWithBalance(api, web3);54 const notOwner = await createEthAccountWithBalance(api, web3);55 const flipper = await deployFlipper(web3, owner);56 const helpers = contractHelpers(web3, owner);57 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;58 await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).send({from: notOwner})).to.rejected;59 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;60 });6162 itWeb3('In generous mode, non-allowlisted user transaction will be sponsored', async ({api, web3}) => {63 const alice = privateKey('//Alice');6465 const owner = await createEthAccountWithBalance(api, web3);66 const caller = await createEthAccountWithBalance(api, web3);6768 const flipper = await deployFlipper(web3, owner);6970 const helpers = contractHelpers(web3, owner);7172 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;73 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});74 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});75 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;7677 await transferBalanceToEth(api, alice, flipper.options.address);7879 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);80 expect(originalFlipperBalance).to.be.not.equal('0');8182 await flipper.methods.flip().send({from: caller});83 expect(await flipper.methods.getValue().call()).to.be.true;8485 // Balance should be taken from flipper instead of caller86 const balanceAfter = await web3.eth.getBalance(flipper.options.address);87 expect(+balanceAfter).to.be.lessThan(+originalFlipperBalance);88 });8990 itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({api, web3}) => {91 const alice = privateKey('//Alice');9293 const owner = await createEthAccountWithBalance(api, web3);94 const caller = createEthAccount(web3);9596 const flipper = await deployFlipper(web3, owner);9798 const helpers = contractHelpers(web3, owner);99 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});100 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});101102 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;103 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});104 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});105 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;106107 await transferBalanceToEth(api, alice, flipper.options.address);108109 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);110 expect(originalFlipperBalance).to.be.not.equal('0');111112 await flipper.methods.flip().send({from: caller});113 expect(await flipper.methods.getValue().call()).to.be.true;114115 // Balance should be taken from flipper instead of caller116 const balanceAfter = await web3.eth.getBalance(flipper.options.address);117 expect(+balanceAfter).to.be.lessThan(+originalFlipperBalance);118 });119120 itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({api, web3}) => {121 const alice = privateKey('//Alice');122123 const owner = await createEthAccountWithBalance(api, web3);124 const caller = createEthAccount(web3);125126 const flipper = await deployFlipper(web3, owner);127128 const helpers = contractHelpers(web3, owner);129130 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;131 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});132 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});133 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;134135 await transferBalanceToEth(api, alice, flipper.options.address);136137 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);138 expect(originalFlipperBalance).to.be.not.equal('0');139140 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/InvalidTransaction::Payment/);141 expect(await flipper.methods.getValue().call()).to.be.false;142143 // Balance should be taken from flipper instead of caller144 const balanceAfter = await web3.eth.getBalance(flipper.options.address);145 expect(+balanceAfter).to.be.equals(+originalFlipperBalance);146 });147148 itWeb3('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({api, web3}) => {149 const alice = privateKey('//Alice');150151 const owner = await createEthAccountWithBalance(api, web3);152 const caller = await createEthAccountWithBalance(api, web3);153 const originalCallerBalance = await web3.eth.getBalance(caller);154155 const flipper = await deployFlipper(web3, owner);156157 const helpers = contractHelpers(web3, owner);158 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});159 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});160161 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;162 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});163 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});164 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;165166 await transferBalanceToEth(api, alice, flipper.options.address);167168 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);169 expect(originalFlipperBalance).to.be.not.equal('0');170171 await flipper.methods.flip().send({from: caller});172 expect(await flipper.methods.getValue().call()).to.be.true;173174 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);175 });176177 itWeb3('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({api, web3}) => {178 const alice = privateKey('//Alice');179180 const owner = await createEthAccountWithBalance(api, web3);181 const caller = await createEthAccountWithBalance(api, web3);182 const originalCallerBalance = await web3.eth.getBalance(caller);183184 const flipper = await deployFlipper(web3, owner);185186 const helpers = contractHelpers(web3, owner);187 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});188 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});189190 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;191 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});192 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 10).send({from: owner});193 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;194195 await transferBalanceToEth(api, alice, flipper.options.address);196197 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);198 expect(originalFlipperBalance).to.be.not.equal('0');199200 await flipper.methods.flip().send({from: caller});201 expect(await flipper.methods.getValue().call()).to.be.true;202 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);203204 await flipper.methods.flip().send({from: caller});205 expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance);206 });207208 // TODO: Find a way to calculate default rate limit209 itWeb3('Default rate limit equals 7200', async ({api, web3}) => {210 const owner = await createEthAccountWithBalance(api, web3);211 const flipper = await deployFlipper(web3, owner);212 const helpers = contractHelpers(web3, owner);213 expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');214 });215216 itWeb3('Sponsoring evm address from substrate collection', async ({api, web3}) => {217 const owner = privateKey('//Alice');218 const userEth = createEthAccount(web3);219 const collectionId = await createCollectionExpectSuccess();220221 {222 const tx = api.tx.unique.setCollectionSponsor(collectionId, owner.address);223 const events = await submitTransactionAsync(owner, tx);224 const result = getCreateCollectionResult(events);225 expect(result.success).to.be.true;226 }227 {228 const tx = api.tx.unique.confirmSponsorship(collectionId);229 const events = await submitTransactionAsync(owner, tx);230 const result = getCreateCollectionResult(events);231 expect(result.success).to.be.true;232 }233234 const address = collectionIdToAddress(collectionId);235 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: userEth, ...GAS_ARGS});236237 { // This part should fail, because user not in access list and user have no money238 const nextTokenId = await contract.methods.nextTokenId().call();239 expect(nextTokenId).to.be.equal('1');240 await expect(contract.methods.mintWithTokenURI(241 userEth,242 nextTokenId,243 'Test URI',244 ).call({from: userEth})).to.be.rejectedWith(/PublicMintingNotAllowed/);245 }246247 {248 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');249 const events = await submitTransactionAsync(owner, tx);250 const result = getCreateCollectionResult(events);251 expect(result.success).to.be.true;252 }253 {254 const tx = api.tx.unique.addToAllowList(collectionId, {Ethereum: userEth});255 const events = await submitTransactionAsync(owner, tx);256 const result = getCreateCollectionResult(events);257 expect(result.success).to.be.true;258 }259 {260 const tx = api.tx.unique.setMintPermission(collectionId, true);261 const events = await submitTransactionAsync(owner, tx);262 const result = getCreateCollectionResult(events);263 expect(result.success).to.be.true;264 }265266 const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);267268 {269 const nextTokenId = await contract.methods.nextTokenId().call();270 expect(nextTokenId).to.be.equal('1');271 const result = await contract.methods.mintWithTokenURI(272 userEth,273 nextTokenId,274 'Test URI',275 ).send({from: userEth});276 const events = normalizeEvents(result.events);277278 expect(events).to.be.deep.equal([279 {280 address,281 event: 'Transfer',282 args: {283 from: '0x0000000000000000000000000000000000000000',284 to: userEth,285 tokenId: nextTokenId,286 },287 },288 ]);289290 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');291 }292293 const [alicesBalanceAfter] = await getBalance(api, [alicesPublicKey]);294 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;295 });296});