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
before · tests/src/creditFeesToTreasury.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';9import {alicesPublicKey, bobsPublicKey} from './accounts';10import privateKey from './substrate/privateKey';11import {IKeyringPair} from '@polkadot/types/types';12import {13  createCollectionExpectSuccess,14  createItemExpectSuccess,15  getGenericResult,16  transferExpectSuccess,17  UNIQUE,18} from './util/helpers';1920import {default as waitNewBlocks} from './substrate/wait-new-blocks';21import {ApiPromise} from '@polkadot/api';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';27const saneMinimumFee = 0.05;28const saneMaximumFee = 0.5;29const createCollectionDeposit = 100;3031let alice: IKeyringPair;32let bob: IKeyringPair;3334// Skip the inflation block pauses if the block is close to inflation block35// until the inflation happens36/*eslint no-async-promise-executor: "off"*/37function skipInflationBlock(api: ApiPromise): Promise<void> {38  const promise = new Promise<void>(async (resolve) => {39    const blockInterval = (await api.consts.inflation.inflationBlockInterval).toNumber();40    const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {41      const currentBlock = head.number.toNumber();42      if (currentBlock % blockInterval < blockInterval - 10) {43        unsubscribe();44        resolve();45      } else {46        console.log(`Skipping inflation block, current block: ${currentBlock}`);47      }48    });49  });5051  return promise;52}5354describe('integration test: Fees must be credited to Treasury:', () => {55  before(async () => {56    await usingApi(async () => {57      alice = privateKey('//Alice');58      bob = privateKey('//Bob');59    });60  });6162  it('Total issuance does not change', async () => {63    await usingApi(async (api) => {64      await skipInflationBlock(api);65      await waitNewBlocks(api, 1);6667      const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();6869      const alicePrivateKey = privateKey('//Alice');70      const amount = 1n;71      const transfer = api.tx.balances.transfer(bobsPublicKey, amount);7273      const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));7475      const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();7677      expect(result.success).to.be.true;78      expect(totalAfter).to.be.equal(totalBefore);79    });80  });8182  it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {83    await usingApi(async (api) => {84      await skipInflationBlock(api);85      await waitNewBlocks(api, 1);8687      const alicePrivateKey = privateKey('//Alice');88      const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();89      const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();9091      const amount = 1n;92      const transfer = api.tx.balances.transfer(bobsPublicKey, amount);93      const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));9495      const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();96      const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();97      const fee = aliceBalanceBefore - aliceBalanceAfter - amount;98      const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;99100      expect(result.success).to.be.true;101      expect(treasuryIncrease).to.be.equal(fee);102    });103  });104105  it('Treasury balance increased by failed tx fee', async () => {106    await usingApi(async (api) => {107      await skipInflationBlock(api);108      await waitNewBlocks(api, 1);109110      const bobPrivateKey = privateKey('//Bob');111      const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();112      const bobBalanceBefore = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();113114      const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);115      await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;116117      const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();118      const bobBalanceAfter = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();119      const fee = bobBalanceBefore - bobBalanceAfter;120      const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;121122      expect(treasuryIncrease).to.be.equal(fee);123    });124  });125126  it('NFT Transactions also send fees to Treasury', async () => {127    await usingApi(async (api) => {128      await skipInflationBlock(api);129      await waitNewBlocks(api, 1);130131      const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();132      const aliceBalanceBefore = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();133134      await createCollectionExpectSuccess();135136      const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();137      const aliceBalanceAfter = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();138      const fee = aliceBalanceBefore - aliceBalanceAfter;139      const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;140141      expect(treasuryIncrease).to.be.equal(fee);142    });143  });144145  it('Fees are sane', async () => {146    await usingApi(async (api) => {147      await skipInflationBlock(api);148      await waitNewBlocks(api, 1);149150      const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();151152      await createCollectionExpectSuccess();153154      const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();155      const fee = aliceBalanceBefore - aliceBalanceAfter;156157      expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;158      expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMinimumFee  + createCollectionDeposit))).to.be.true;159    });160  });161162  it('NFT Transfer fee is close to 0.1 Unique', async () => {163    await usingApi(async (api) => {164      await skipInflationBlock(api);165      await waitNewBlocks(api, 1);166167      const collectionId = await createCollectionExpectSuccess();168      const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');169170      const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();171      await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');172      const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();173174      const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);175      const expectedTransferFee = 0.1;176      // fee drifts because of NextFeeMultiplier177      const tolerance = 0.001;178179      expect(Math.abs(fee - expectedTransferFee)).to.be.lessThan(tolerance);180    });181  });182183});
modifiedtests/src/eth/payable.test.tsdiffbeforeafterboth
--- a/tests/src/eth/payable.test.ts
+++ b/tests/src/eth/payable.test.ts
@@ -54,7 +54,7 @@
     expect(await contract.methods.getUnaccounted().call()).to.be.equal('10000');
   });
 
-  itWeb3('Balance can be retrieved from evm contract', async({api, web3}) => {
+  itWeb3.only('Balance can be retrieved from evm contract', async({api, web3}) => {
     const FEE_BALANCE = 10n ** 18n;
     const CONTRACT_BALANCE = 10n ** 14n;
 
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;