Skip to content

Commit

Permalink
Merge branch 'develop' into ci/fix-polkadot-image
Browse files Browse the repository at this point in the history
  • Loading branch information
BuddyGlas committed Jun 26, 2024
2 parents 17ba9b7 + 0ceea0a commit 26a694e
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 139 deletions.
47 changes: 19 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions js-packages/tests/creditFeesToTreasury.seqtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import type {IKeyringPair} from '@polkadot/types/types';
import {ApiPromise} from '@polkadot/api';
import {usingPlaygrounds, expect, itSub} from '@unique/test-utils/util.js';
import type {u32} from '@polkadot/types-codec';
import { itEth } from '@unique/test-utils/eth/util.js';
import { ITransactionResult } from '@unique-nft/playgrounds/types';

const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
const saneMinimumFee = 0.05;
Expand Down Expand Up @@ -163,4 +165,36 @@ describe('integration test: Fees must be credited to Treasury:', () => {

expect(Math.abs(fee - expectedTransferFee)).to.be.lessThan(tolerance);
});

itEth('Evm Transactions send fees to Treasury', async ({helper}) => {
const value = helper.balance.getOneTokenNominal();
const gasPrice = await helper.getWeb3().eth.getGasPrice();
let result = null;

const lambda = async () => {
result = await helper.executeExtrinsic(alice, 'api.tx.evm.call', [
helper.address.substrateToEth(alice.address),
helper.address.substrateToEth(bob.address),
'0x',
value,
25_000,
gasPrice,
null,
null,
[],
]);
};

const totalPaid = await helper.arrange.calculcateFee({ Substrate: alice.address }, lambda);
const evmFees = totalPaid - value;

const treasuryDepoosited = (result as unknown as ITransactionResult).result.events
.filter(({ event: { method, section } }) => section == 'treasury' && method == 'Deposit')
.map(({ event: { data } }) => data[0].toJSON());

const deposit = BigInt(treasuryDepoosited[0]);

expect(deposit).to.be.equal(evmFees);
});

});
50 changes: 48 additions & 2 deletions js-packages/tests/limits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from '@u

describe('Number of tokens per address (NFT)', () => {
let alice: IKeyringPair;
let bob: IKeyringPair;

before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
const donor = await privateKey({url: import.meta.url});
[alice] = await helper.arrange.createAccounts([10n], donor);
[alice, bob] = await helper.arrange.createAccounts([10n, 0n], donor);
});
});

Expand Down Expand Up @@ -51,17 +52,40 @@ describe('Number of tokens per address (NFT)', () => {
await collection.burnToken(alice, 1);
await expect(collection.burn(alice)).to.be.not.rejected;
});

itSub('Can transfer tokens to address equal to accountTokenOwnershipLimit', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice, {});
await collection.setLimits(alice, {accountTokenOwnershipLimit: 1});

// Limit 1 - can transfer #1 token
const tkn1 = await collection.mintToken(alice);
await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address});

// Limit 1 - cannot transfer #2 token
const tkn2 = await collection.mintToken(alice);
await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);

// Increase limit to 2
// Now can transfer token #2
await collection.setLimits(alice, {accountTokenOwnershipLimit: 2});
await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address});

// But cannot transfer token #3
const tkn3 = await collection.mintToken(alice);
await expect(collection.transferToken(alice, tkn3.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);
});
});

describe('Number of tokens per address (ReFungible)', () => {
let alice: IKeyringPair;
let bob: IKeyringPair;

before(async function() {
await usingPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);

const donor = await privateKey({url: import.meta.url});
[alice] = await helper.arrange.createAccounts([10n], donor);
[alice, bob] = await helper.arrange.createAccounts([10n, 0n], donor);
});
});

Expand Down Expand Up @@ -89,6 +113,28 @@ describe('Number of tokens per address (ReFungible)', () => {
await collection.burnToken(alice, 1);
await expect(collection.burn(alice)).to.be.not.rejected;
});

itSub('Can transfer tokens to address equal to accountTokenOwnershipLimit', async ({helper}) => {
const collection = await helper.rft.mintCollection(alice, {});
await collection.setLimits(alice, {accountTokenOwnershipLimit: 1});

// Limit 1 - can transfer #1 token
const tkn1 = await collection.mintToken(alice);
await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address});

// Limit 1 - cannot transfer #2 token
const tkn2 = await collection.mintToken(alice);
await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);

// Increase limit to 2
// Now can transfer token #2
await collection.setLimits(alice, {accountTokenOwnershipLimit: 2});
await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address});

// But cannot transfer token #3
const tkn3 = await collection.mintToken(alice);
await expect(collection.transferToken(alice, tkn3.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);
});
});

// todo:playgrounds skipped ~ postponed
Expand Down
32 changes: 18 additions & 14 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,24 @@ fn genesis_patch() -> serde_json::Value {
.collect::<Vec<_>>(),
},

"session": {
"keys": invulnerables.into_iter()
.map(|name| {
let account = get_account_id_from_seed::<sr25519::Public>(name);
let aura = get_from_seed::<AuraId>(name);

(
/* account id: */ account.clone(),
/* validator id: */ account,
/* session keys: */ SessionKeys { aura },
)
})
.collect::<Vec<_>>()
},
// We don't have Session pallet in production anywhere,
// Adding this config makes baedeker think we have pallet-session, and it tries to
// reconfigure chain using it, which makes no sense, because then aura knows no
// authority, as baedeker expects them to be configured by session pallet.
// "session": {
// "keys": invulnerables.into_iter()
// .map(|name| {
// let account = get_account_id_from_seed::<sr25519::Public>(name);
// let aura = get_from_seed::<AuraId>(name);
//
// (
// /* account id: */ account.clone(),
// /* validator id: */ account,
// /* session keys: */ SessionKeys { aura },
// )
// })
// .collect::<Vec<_>>()
// },

"sudo": {
"key": get_account_id_from_seed::<sr25519::Public>("Alice"),
Expand Down
Loading

0 comments on commit 26a694e

Please sign in to comment.