git.delta.rocks / unique-network / refs/commits / fced7659a53c

difftreelog

Tests can build

Greg Zaitsev2021-06-25parent: #90fcef9.patch.diff
in: master

8 files changed

modifiedCargo.lockdiffbeforeafterboth
5993 "sp-std",5993 "sp-std",
5994]5994]
5995
5996[[package]]
5997name = "pallet-scheduler"
5998version = "3.0.0"
5999dependencies = [
6000 "frame-benchmarking",
6001 "frame-support",
6002 "frame-system",
6003 "log",
6004 "parity-scale-codec 2.1.3",
6005 "serde",
6006 "sp-core",
6007 "sp-io",
6008 "sp-runtime",
6009 "sp-std",
6010 "substrate-test-utils",
6011 "up-sponsorship",
6012]
60135995
6014[[package]]5996[[package]]
6015name = "pallet-scheduler"5997name = "pallet-scheduler"
6026 "sp-std",6008 "sp-std",
6027]6009]
6010
6011[[package]]
6012name = "pallet-scheduler"
6013version = "3.0.0"
6014dependencies = [
6015 "frame-benchmarking",
6016 "frame-support",
6017 "frame-system",
6018 "log",
6019 "parity-scale-codec 2.1.3",
6020 "serde",
6021 "sp-core",
6022 "sp-io",
6023 "sp-runtime",
6024 "sp-std",
6025 "substrate-test-utils",
6026 "up-sponsorship",
6027]
60286028
6029[[package]]6029[[package]]
6030name = "pallet-session"6030name = "pallet-session"
modifiedlaunch-config.jsondiffbeforeafterboth
45 "nodes": [45 "nodes": [
46 {46 {
47 "port": 31200,47 "port": 31200,
48 "wsPort": "9944",
48 "name": "alice",49 "name": "alice",
49 "flags": []50 "flags": []
50 }51 },
52 {
53 "port": 31201,
54 "wsPort": "9945",
55 "name": "bob",
56 "flags": []
57 }
51 ]58 ]
52 }59 }
53 ],60 ],
modifiedruntime/src/lib.rsdiffbeforeafterboth
216/// by Operational extrinsics.216/// by Operational extrinsics.
217const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);217const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
218/// We allow for 2 seconds of compute with a 6 second average block time.218/// We allow for 2 seconds of compute with a 6 second average block time.
219const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;219const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2;
220220
221parameter_types! {221parameter_types! {
222 pub const BlockHashCount: BlockNumber = 2400;222 pub const BlockHashCount: BlockNumber = 2400;
modifiedtests/src/config.tsdiffbeforeafterboth
6import process from 'process';6import process from 'process';
77
8const config = {8const config = {
9 substrateUrl: process.env.substrateUrl || 'ws://127.0.0.1:9844'9 substrateUrl: process.env.substrateUrl || 'ws://127.0.0.1:9944'
10}10}
1111
12export default config;12export default config;
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
177 const result = getGenericResult(events);177 const result = getGenericResult(events);
178 expect(result.success).to.be.true;178 expect(result.success).to.be.true;
179179
180 await transferFromExpectSuccess(collectionId, tokenId, bob, contract.address.toString(), charlie, 1, 'NFT');180 await transferFromExpectSuccess(collectionId, tokenId, bob, normalizeAccountId(contract.address.toString()), charlie, 1, 'NFT');
181 });181 });
182 });182 });
183183
modifiedtests/src/removeFromWhiteList.test.tsdiffbeforeafterboth
16 findNotExistingCollection,16 findNotExistingCollection,
17 removeFromWhiteListExpectFailure,17 removeFromWhiteListExpectFailure,
18 disableWhiteListExpectSuccess,18 disableWhiteListExpectSuccess,
19 normalizeAccountId
19} from './util/helpers';20} from './util/helpers';
20import { IKeyringPair } from '@polkadot/types/types';21import { IKeyringPair } from '@polkadot/types/types';
21import privateKey from './substrate/privateKey';22import privateKey from './substrate/privateKey';
40 await enableWhiteListExpectSuccess(alice, collectionId);41 await enableWhiteListExpectSuccess(alice, collectionId);
41 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);42 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
4243
43 await removeFromWhiteListExpectSuccess(alice, collectionId, bob.address);44 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));
44 expect(await isWhitelisted(collectionId, bob.address)).to.be.false;45 expect(await isWhitelisted(collectionId, bob.address)).to.be.false;
45 });46 });
46 });47 });
52 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);53 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);
53 await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);54 await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
5455
55 await removeFromWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);56 await removeFromWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, normalizeAccountId(bob.address));
56 });57 });
57 });58 });
58});59});
72 await usingApi(async (api) => {73 await usingApi(async (api) => {
73 const collectionId = await findNotExistingCollection(api);74 const collectionId = await findNotExistingCollection(api);
7475
75 await removeFromWhiteListExpectFailure(alice, collectionId, bob.address);76 await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));
76 });77 });
77 });78 });
7879
83 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);84 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
84 await destroyCollectionExpectSuccess(collectionId);85 await destroyCollectionExpectSuccess(collectionId);
8586
86 await removeFromWhiteListExpectFailure(alice, collectionId, bob.address);87 await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));
87 });88 });
88 });89 });
89});90});
modifiedtests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth
45 const [contract, deployer] = await deployFlipper(api);45 const [contract, deployer] = await deployFlipper(api);
4646
47 let flipValueBefore = await getFlipValue(contract, deployer);47 let flipValueBefore = await getFlipValue(contract, deployer);
48 const flip = contract.exec('flip', value, gasLimit);48 const flip = contract.tx.flip(value, gasLimit);
49 await submitTransactionAsync(bob, flip);49 await submitTransactionAsync(bob, flip);
50 const flipValueAfter = await getFlipValue(contract,deployer);50 const flipValueAfter = await getFlipValue(contract,deployer);
51 expect(flipValueAfter).to.be.eq(!flipValueBefore, `Anyone can call new contract.`);51 expect(flipValueAfter).to.be.eq(!flipValueBefore, `Anyone can call new contract.`);
5252
53 const deployerCanFlip = async () => {53 const deployerCanFlip = async () => {
54 let flipValueBefore = await getFlipValue(contract, deployer);54 let flipValueBefore = await getFlipValue(contract, deployer);
55 const deployerFlip = contract.exec('flip', value, gasLimit);55 const deployerFlip = contract.tx.flip(value, gasLimit);
56 await submitTransactionAsync(deployer, deployerFlip);56 await submitTransactionAsync(deployer, deployerFlip);
57 const aliceFlip1Response = await getFlipValue(contract, deployer);57 const aliceFlip1Response = await getFlipValue(contract, deployer);
58 expect(aliceFlip1Response).to.be.eq(!flipValueBefore, `Deployer always can flip.`);58 expect(aliceFlip1Response).to.be.eq(!flipValueBefore, `Deployer always can flip.`);
62 flipValueBefore = await getFlipValue(contract, deployer);62 flipValueBefore = await getFlipValue(contract, deployer);
63 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);63 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);
64 const enableResult = await submitTransactionAsync(deployer, enableWhiteListTx);64 const enableResult = await submitTransactionAsync(deployer, enableWhiteListTx);
65 const flipWithEnabledWhiteList = contract.exec('flip', value, gasLimit);65 const flipWithEnabledWhiteList = contract.tx.flip(value, gasLimit);
66 await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledWhiteList)).to.be.rejected;66 await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledWhiteList)).to.be.rejected;
67 const flipValueAfterEnableWhiteList = await getFlipValue(contract, deployer);67 const flipValueAfterEnableWhiteList = await getFlipValue(contract, deployer);
68 expect(flipValueAfterEnableWhiteList).to.be.eq(flipValueBefore, `Enabling whitelist doesn't make it possible to call contract for everyone.`);68 expect(flipValueAfterEnableWhiteList).to.be.eq(flipValueBefore, `Enabling whitelist doesn't make it possible to call contract for everyone.`);
72 flipValueBefore = await getFlipValue(contract, deployer);72 flipValueBefore = await getFlipValue(contract, deployer);
73 const addBobToWhiteListTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);73 const addBobToWhiteListTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);
74 const addBobResult = await submitTransactionAsync(deployer, addBobToWhiteListTx);74 const addBobResult = await submitTransactionAsync(deployer, addBobToWhiteListTx);
75 const flipWithWhitelistedBob = contract.exec('flip', value, gasLimit);75 const flipWithWhitelistedBob = contract.tx.flip(value, gasLimit);
76 await submitTransactionAsync(bob, flipWithWhitelistedBob);76 await submitTransactionAsync(bob, flipWithWhitelistedBob);
77 const flipAfterWhiteListed = await getFlipValue(contract,deployer);77 const flipAfterWhiteListed = await getFlipValue(contract,deployer);
78 expect(flipAfterWhiteListed).to.be.eq(!flipValueBefore, `Bob was whitelisted, now he can flip.`);78 expect(flipAfterWhiteListed).to.be.eq(!flipValueBefore, `Bob was whitelisted, now he can flip.`);
82 flipValueBefore = await getFlipValue(contract, deployer);82 flipValueBefore = await getFlipValue(contract, deployer);
83 const removeBobFromWhiteListTx = api.tx.nft.removeFromContractWhiteList(contract.address, bob.address);83 const removeBobFromWhiteListTx = api.tx.nft.removeFromContractWhiteList(contract.address, bob.address);
84 const removeBobResult = await submitTransactionAsync(deployer, removeBobFromWhiteListTx);84 const removeBobResult = await submitTransactionAsync(deployer, removeBobFromWhiteListTx);
85 const bobRemoved = contract.exec('flip', value, gasLimit);85 const bobRemoved = contract.tx.flip(value, gasLimit);
86 await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;86 await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;
87 const afterBobRemoved = await getFlipValue(contract, deployer);87 const afterBobRemoved = await getFlipValue(contract, deployer);
88 expect(afterBobRemoved).to.be.eq(flipValueBefore, `Bob can't call contract, now when he is removeed from white list.`);88 expect(afterBobRemoved).to.be.eq(flipValueBefore, `Bob can't call contract, now when he is removeed from white list.`);
92 flipValueBefore = await getFlipValue(contract, deployer);92 flipValueBefore = await getFlipValue(contract, deployer);
93 const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);93 const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);
94 const disableWhiteListResult = await submitTransactionAsync(deployer, disableWhiteListTx);94 const disableWhiteListResult = await submitTransactionAsync(deployer, disableWhiteListTx);
95 const whiteListDisabledFlip = contract.exec('flip', value, gasLimit);95 const whiteListDisabledFlip = contract.tx.flip(value, gasLimit);
96 await submitTransactionAsync(bob, whiteListDisabledFlip);96 await submitTransactionAsync(bob, whiteListDisabledFlip);
97 const afterWhiteListDisabled = await getFlipValue(contract,deployer);97 const afterWhiteListDisabled = await getFlipValue(contract,deployer);
98 expect(afterWhiteListDisabled).to.be.eq(!flipValueBefore, `Anyone can call contract with disabled whitelist.`);98 expect(afterWhiteListDisabled).to.be.eq(!flipValueBefore, `Anyone can call contract with disabled whitelist.`);
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
29} | {29} | {
30 ethereum: string,30 ethereum: string,
31};31};
32export function normalizeAccountId(input: string | CrossAccountId | IKeyringPair): CrossAccountId {32export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {
33 if (typeof input === 'string')33 if (typeof input === 'string')
34 return { substrate: input };34 return { substrate: input };
35 if ('address' in input) {35 if ('address' in input) {
36 return { substrate: input.address };36 return { substrate: input.address };
37 }37 }
38 if ('ethereum' in input) {38 if ('ethereum' in input) {
39 input.ethereum = input.ethereum.toLowerCase();39 input.ethereum = input.ethereum.toLowerCase();
40 return input;
40 }41 }
42
43 // AccountId
41 return input;44 return {substrate: input.toString()}
42}45}
43export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {46export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {
44 input = normalizeAccountId(input);47 input = normalizeAccountId(input);