git.delta.rocks / unique-network / refs/commits / 950af3d1ff1e

difftreelog

Merge pull request #254 from UniqueNetwork/feature/decimals-18-v2

kozyrevdev2021-12-02parents: #0a9dcd5 #a3d7303.patch.diff
in: master
change decimals from 15 to 18

8 files changed

modifiedlaunch-config-westend.jsondiffbeforeafterboth
--- a/launch-config-westend.json
+++ b/launch-config-westend.json
@@ -79,9 +79,9 @@
     },
     "parachains": [
         {
-            "bin": "../unique-chain/target/release/nft",
+            "bin": "../unique-chain/target/release/unique-collator",
             "chain": "westend-local",
-            "balance": "1000000000000000000000",
+            "balance": "1000000000000000000000000",
             "nodes": [
                 {
                     "port": 31200,
modifiedlaunch-config.jsondiffbeforeafterboth
--- a/launch-config.json
+++ b/launch-config.json
@@ -57,7 +57,7 @@
         {
             "bin": "../unique-chain/target/release/unique-collator",
             "id": "2000",
-            "balance": "1000000000000000000000",
+            "balance": "1000000000000000000000000",
             "nodes": [
                 {
                     "port": 31200,
modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -53,9 +53,9 @@
 
 pub fn development_config(id: ParaId) -> ChainSpec {
 	let mut properties = Map::new();
-	properties.insert("tokenSymbol".into(), "testUNQ".into());
+	properties.insert("tokenSymbol".into(), "OPL".into());
 	properties.insert("tokenDecimals".into(), 15.into());
-	properties.insert("ss58Format".into(), 42.into()); // Generic Substrate wildcard (SS58 checksum preimage)
+	properties.insert("ss58Format".into(), 42.into());
 
 	ChainSpec::from_genesis(
 		// Name
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -243,7 +243,7 @@
 impl FeeCalculator for FixedFee {
 	fn min_gas_price() -> U256 {
 		// Targeting 0.15 UNQ per transfer
-		1_024_947_215u32.into()
+		1_024_947_215_000u64.into()
 	}
 }
 
@@ -403,7 +403,7 @@
 	type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;
 }
 
-pub const MICROUNIQUE: Balance = 1_000_000_000;
+pub const MICROUNIQUE: Balance = 1_000_000_000_000;
 pub const MILLIUNIQUE: Balance = 1_000 * MICROUNIQUE;
 pub const CENTIUNIQUE: Balance = 10 * MILLIUNIQUE;
 pub const UNIQUE: Balance = 100 * CENTIUNIQUE;
@@ -481,7 +481,7 @@
 	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
 		smallvec!(WeightToFeeCoefficient {
 			// Targeting 0.1 Unique per NFT transfer
-			coeff_integer: 142_688u32.into(),
+			coeff_integer: 142_688_000u32.into(),
 			coeff_frac: Perbill::zero(),
 			negative: false,
 			degree: 1,
modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -21,6 +21,7 @@
   normalizeAccountId,
   addCollectionAdminExpectSuccess,
   getCreatedCollectionCount,
+  UNIQUE,
 } from './util/helpers';
 import {Keyring} from '@polkadot/api';
 import {IKeyringPair} from '@polkadot/types/types';
@@ -198,7 +199,7 @@
       const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
 
       // Try again after Zero gets some balance - now it should succeed
-      const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
+      const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);
       await submitTransactionAsync(alice, balancetx);
       const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);
       const result2 = getGenericResult(events2);
@@ -232,7 +233,7 @@
       const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
 
       // Try again after Zero gets some balance - now it should succeed
-      const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
+      const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);
       await submitTransactionAsync(alice, balancetx);
       const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);
       const result2 = getGenericResult(events2);
@@ -268,7 +269,7 @@
       expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
 
       // Try again after Zero gets some balance - now it should succeed
-      const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
+      const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);
       await submitTransactionAsync(alice, balancetx);
       const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);
       const result2 = getGenericResult(events2);
@@ -307,7 +308,7 @@
       const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
 
       // Try again after Zero gets some balance - now it should succeed
-      const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
+      const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);
       await submitTransactionAsync(alice, balancetx);
       await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
 
modifiedtests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth
--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -154,8 +154,8 @@
       const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
       const fee = aliceBalanceBefore - aliceBalanceAfter;
 
-      expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
-      expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMinimumFee  + createCollectionDeposit))).to.be.true;
+      expect(fee / UNIQUE < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
+      expect(fee / UNIQUE < BigInt(Math.ceil(saneMinimumFee  + createCollectionDeposit))).to.be.true;
     });
   });
 
modifiedtests/src/eth/payable.test.tsdiffbeforeafterboth
before · tests/src/eth/payable.test.ts
1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import {submitTransactionAsync} from '../substrate/substrate-api';4import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';5import {evmToAddress} from '@polkadot/util-crypto';6import {getGenericResult} from '../util/helpers';7import {getBalanceSingle, transferBalanceExpectSuccess} from '../substrate/get-balance';89describe('EVM payable contracts', () => {10  itWeb3('Evm contract can receive wei from eth account', async ({api, web3}) => {11    const deployer = await createEthAccountWithBalance(api, web3);12    const contract = await deployCollector(web3, deployer);1314    await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: '10000', ...GAS_ARGS});1516    expect(await contract.methods.getCollected().call()).to.be.equal('10000');17  });1819  itWeb3('Evm contract can receive wei from substrate account', async ({api, web3}) => {20    const deployer = await createEthAccountWithBalance(api, web3);21    const contract = await deployCollector(web3, deployer);22    const alice = privateKey('//Alice');2324    // Transaction fee/value will be payed from subToEth(sender) evm balance,25    // which is backed by evmToAddress(subToEth(sender)) substrate balance26    await transferBalanceToEth(api, alice, subToEth(alice.address));2728    {29      const tx = api.tx.evm.call(30        subToEth(alice.address),31        contract.options.address,32        contract.methods.giveMoney().encodeABI(),33        '10000',34        GAS_ARGS.gas,35        await web3.eth.getGasPrice(),36        null,37      );38      const events = await submitTransactionAsync(alice, tx);39      const result = getGenericResult(events);40      expect(result.success).to.be.true;41    }4243    expect(await contract.methods.getCollected().call()).to.be.equal('10000');44  });4546  // We can't handle sending balance to backing storage of evm balance, because evmToAddress operation is irreversible47  itWeb3('Wei sent directly to backing storage of evm contract balance is unaccounted', async({api, web3}) => {48    const deployer = await createEthAccountWithBalance(api, web3);49    const contract = await deployCollector(web3, deployer);50    const alice = privateKey('//Alice');5152    await transferBalanceExpectSuccess(api, alice, evmToAddress(contract.options.address), '10000');5354    expect(await contract.methods.getUnaccounted().call()).to.be.equal('10000');55  });5657  itWeb3('Balance can be retrieved from evm contract', async({api, web3}) => {58    const FEE_BALANCE = 10n ** 18n;59    const CONTRACT_BALANCE = 10n ** 14n;6061    const deployer = await createEthAccountWithBalance(api, web3);62    const contract = await deployCollector(web3, deployer);63    const alice = privateKey('//Alice');6465    await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), ...GAS_ARGS});6667    const receiver = privateKey(`//Receiver${Date.now()}`);6869    // First receive balance on eth balance of bob70    {71      const ethReceiver = subToEth(receiver.address);72      expect(await web3.eth.getBalance(ethReceiver)).to.be.equal('0');73      await contract.methods.withdraw(ethReceiver).send({from: deployer});74      expect(await web3.eth.getBalance(ethReceiver)).to.be.equal(CONTRACT_BALANCE.toString());75    }7677    // Some balance is required to pay fee for evm.withdraw call78    await transferBalanceExpectSuccess(api, alice, receiver.address, FEE_BALANCE.toString());7980    // Withdraw balance from eth to substrate81    {82      const initialReceiverBalance = await getBalanceSingle(api, receiver.address);83      const tx = api.tx.evm.withdraw(84        subToEth(receiver.address),85        CONTRACT_BALANCE.toString(),86      );87      const events = await submitTransactionAsync(receiver, tx);88      const result = getGenericResult(events);89      expect(result.success).to.be.true;90      const finalReceiverBalance = await getBalanceSingle(api, receiver.address);9192      expect(finalReceiverBalance > initialReceiverBalance).to.be.true;93    }94  });95});
after · tests/src/eth/payable.test.ts
1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import {submitTransactionAsync} from '../substrate/substrate-api';4import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';5import {evmToAddress} from '@polkadot/util-crypto';6import {getGenericResult} from '../util/helpers';7import {getBalanceSingle, transferBalanceExpectSuccess} from '../substrate/get-balance';89describe('EVM payable contracts', () => {10  itWeb3('Evm contract can receive wei from eth account', async ({api, web3}) => {11    const deployer = await createEthAccountWithBalance(api, web3);12    const contract = await deployCollector(web3, deployer);1314    await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: '10000', ...GAS_ARGS});1516    expect(await contract.methods.getCollected().call()).to.be.equal('10000');17  });1819  itWeb3('Evm contract can receive wei from substrate account', async ({api, web3}) => {20    const deployer = await createEthAccountWithBalance(api, web3);21    const contract = await deployCollector(web3, deployer);22    const alice = privateKey('//Alice');2324    // Transaction fee/value will be payed from subToEth(sender) evm balance,25    // which is backed by evmToAddress(subToEth(sender)) substrate balance26    await transferBalanceToEth(api, alice, subToEth(alice.address));2728    {29      const tx = api.tx.evm.call(30        subToEth(alice.address),31        contract.options.address,32        contract.methods.giveMoney().encodeABI(),33        '10000',34        GAS_ARGS.gas,35        await web3.eth.getGasPrice(),36        null,37      );38      const events = await submitTransactionAsync(alice, tx);39      const result = getGenericResult(events);40      expect(result.success).to.be.true;41    }4243    expect(await contract.methods.getCollected().call()).to.be.equal('10000');44  });4546  // We can't handle sending balance to backing storage of evm balance, because evmToAddress operation is irreversible47  itWeb3('Wei sent directly to backing storage of evm contract balance is unaccounted', async({api, web3}) => {48    const deployer = await createEthAccountWithBalance(api, web3);49    const contract = await deployCollector(web3, deployer);50    const alice = privateKey('//Alice');5152    await transferBalanceExpectSuccess(api, alice, evmToAddress(contract.options.address), '10000');5354    expect(await contract.methods.getUnaccounted().call()).to.be.equal('10000');55  });5657  itWeb3.only('Balance can be retrieved from evm contract', async({api, web3}) => {58    const FEE_BALANCE = 10n ** 18n;59    const CONTRACT_BALANCE = 10n ** 14n;6061    const deployer = await createEthAccountWithBalance(api, web3);62    const contract = await deployCollector(web3, deployer);63    const alice = privateKey('//Alice');6465    await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), ...GAS_ARGS});6667    const receiver = privateKey(`//Receiver${Date.now()}`);6869    // First receive balance on eth balance of bob70    {71      const ethReceiver = subToEth(receiver.address);72      expect(await web3.eth.getBalance(ethReceiver)).to.be.equal('0');73      await contract.methods.withdraw(ethReceiver).send({from: deployer});74      expect(await web3.eth.getBalance(ethReceiver)).to.be.equal(CONTRACT_BALANCE.toString());75    }7677    // Some balance is required to pay fee for evm.withdraw call78    await transferBalanceExpectSuccess(api, alice, receiver.address, FEE_BALANCE.toString());7980    // Withdraw balance from eth to substrate81    {82      const initialReceiverBalance = await getBalanceSingle(api, receiver.address);83      const tx = api.tx.evm.withdraw(84        subToEth(receiver.address),85        CONTRACT_BALANCE.toString(),86      );87      const events = await submitTransactionAsync(receiver, tx);88      const result = getGenericResult(events);89      expect(result.success).to.be.true;90      const finalReceiverBalance = await getBalanceSingle(api, receiver.address);9192      expect(finalReceiverBalance > initialReceiverBalance).to.be.true;93    }94  });95});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -69,7 +69,7 @@
 
 export const U128_MAX = (1n << 128n) - 1n;
 
-const MICROUNIQUE = 1_000_000_000n;
+const MICROUNIQUE = 1_000_000_000_000n;
 const MILLIUNIQUE = 1_000n * MICROUNIQUE;
 const CENTIUNIQUE = 10n * MILLIUNIQUE;
 export const UNIQUE = 100n * CENTIUNIQUE;