Skip to content

Commit

Permalink
Merge pull request #1 from rmrk-team/master
Browse files Browse the repository at this point in the history
Sync changes from main repo
  • Loading branch information
spenweb authored Sep 1, 2022
2 parents c2109c4 + 0b29d56 commit e6be598
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 511 deletions.
4 changes: 3 additions & 1 deletion cli/consolidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ const consolidate = async () => {
const con = new Consolidator(ss58Format);

const ret = await con.consolidate(remarks);
// Optimisation: return last 500 invalid items
ret.invalid = ret.invalid.slice(ret.invalid.length - 500);

//@ts-ignore
// @ts-ignore
BigInt.prototype.toJSON = function () {
return this.toString();
};
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rmrk-tools",
"version": "2.0.85",
"version": "2.0.90",
"description": "Suite of libraries implementing RMRK.app specs",
"repository": {
"type": "git",
Expand All @@ -26,7 +26,7 @@
"lint": "tsc --noEmit && eslint '*/**/*.{js,ts,tsx}' --quiet",
"lint:fix": "tsc --noEmit && eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
"cli:fetch": "ts-node --project tsconfig.cli.json cli/fetch.ts",
"cli:consolidate": "ts-node --project tsconfig.cli.json cli/consolidate",
"cli:consolidate": "NODE_OPTIONS='--max-old-space-size=8144' ts-node --project tsconfig.cli.json cli/consolidate",
"cli:seed": "ts-node --project tsconfig.cli.json cli/seed",
"cli:getevents": "ts-node --project tsconfig.cli.json cli/getevents",
"cli:validate": "ts-node --project tsconfig.cli.json src/validate",
Expand Down Expand Up @@ -55,10 +55,10 @@
"@babel/preset-env": "^7.13.9",
"@babel/preset-typescript": "^7.13.0",
"@pinata/sdk": "^1.1.13",
"@polkadot/api": "^8.10.1",
"@polkadot/keyring": "^9.6.2",
"@polkadot/util-crypto": "^9.6.2",
"@polkadot/x-randomvalues": "^9.6.2",
"@polkadot/api": "^9.0.1",
"@polkadot/keyring": "^10.1.2",
"@polkadot/util-crypto": "^10.1.2",
"@polkadot/x-randomvalues": "^10.1.2",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
Expand Down Expand Up @@ -89,7 +89,7 @@
"webpack-cli": "^4.5.0"
},
"dependencies": {
"@polkadot/api-augment": "^8.10.1",
"@polkadot/api-augment": "^9.0.1",
"JSONStream": "^1.3.5",
"chalk": "^4.1.0",
"emoji-regex": "^9.2.2",
Expand All @@ -102,9 +102,9 @@
"winston": "^3.3.3"
},
"peerDependency": {
"@polkadot/api": "^8.x",
"@polkadot/keyring": "^9.x",
"@polkadot/util-crypto": "^9.x",
"@polkadot/util": "^9.x"
"@polkadot/api": "^9.x",
"@polkadot/keyring": "^10.x",
"@polkadot/util-crypto": "^10.x",
"@polkadot/util": "^10.x"
}
}
24 changes: 1 addition & 23 deletions src/rmrk2.0.0/tools/consolidator/interactions/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,10 @@ export const listForSaleInteraction = async (
`[${OP_TYPES.LIST}] Attempting to list non-owned NFT ${listEntity.id}, real rootowner: ${rootowner}`
);
}

if (listEntity.price !== BigInt(0)) {
validateTransferability(nft, remark, OP_TYPES.LIST);
}

if (nft.children && nft.children.length > 0) {
const promises = nft.children.map(async (child) => {
const childNftConsolidated = await dbAdapter.getNFTById(child.id);
const childNft = consolidatedNFTtoInstance(childNftConsolidated);
if (childNft?.forsale && childNftConsolidated) {
childNft.addChange({
field: "forsale",
old: childNft.forsale,
new: BigInt(0),
caller: remark.caller,
block: remark.block,
opType: OP_TYPES.LIST,
} as Change);
childNft.forsale = BigInt(0);
await dbAdapter.updateNFTList(childNft, childNftConsolidated);
}
return childNft;
});

await Promise.all(promises);
}

if (listEntity.price !== nft.forsale) {
nft.addChange({
Expand Down
93 changes: 0 additions & 93 deletions test/2.0.0/consolidator/__snapshots__/list.test.ts.snap

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

25 changes: 7 additions & 18 deletions test/2.0.0/consolidator/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ describe("rmrk2.0.0 Consolidator: LIST", () => {
expect(await consolidator.consolidate(remarks)).toMatchSnapshot();
});

it("Should update children to forsale 0", async () => {
const remarks = getRemarksFromBlocksMock([
...getSetupRemarks(),
...getBlockCallsMock(mintNftMock2().mint(mintNftMock(3).getId())),
...getBlockCallsMock(mintNftMock2(4).list(BigInt(1e12))),
...getBlockCallsMock(mintNftMock(3).list(BigInt(1e12))),
]);
const consolidator = new Consolidator();
expect(await consolidator.consolidate(remarks)).toMatchSnapshot();
});

it("Should prevent to LIST non-existent NFT", async () => {
const remarks = getRemarksFromBlocksMock([
...getBlockCallsMock(mintNftMock(3).list(BigInt(1e12))),
Expand Down Expand Up @@ -100,7 +89,7 @@ describe("rmrk2.0.0 Consolidator: LIST", () => {
const consolidator = new Consolidator();
expect(await consolidator.consolidate(remarks)).toMatchSnapshot();
});

it("Should invalidate LIST after transferable block number passed with negative transfer value", async () => {
const remarks = getRemarksFromBlocksMock([
...getBlockCallsMock(createCollectionMock().create()),
Expand All @@ -114,7 +103,7 @@ describe("rmrk2.0.0 Consolidator: LIST", () => {
"[LIST] Attempting to LIST non-transferable NFT 3-d43593c715a56da27d-KANARIABIRDS-KANR-00000777. It was transferable until block 4 but tx made at block 5"
);
});

it("Should allow DE-LIST after transferable block number passed with negative transfer value", async () => {
const remarks = getRemarksFromBlocksMock([
...getBlockCallsMock(createCollectionMock().create()),
Expand All @@ -131,7 +120,7 @@ describe("rmrk2.0.0 Consolidator: LIST", () => {
const consolidator = new Consolidator();
expect(await consolidator.consolidate(remarks)).toMatchSnapshot();
});

it("Should allow LIST until transferable block number reached with negative transfer value", async () => {
const remarks = getRemarksFromBlocksMock([
...getBlockCallsMock(createCollectionMock().create()),
Expand All @@ -141,7 +130,7 @@ describe("rmrk2.0.0 Consolidator: LIST", () => {
const consolidator = new Consolidator();
expect(await consolidator.consolidate(remarks)).toMatchSnapshot();
});

it("Should allow DE-LIST before transferable block number reached with negative transfer value", async () => {
const remarks = getRemarksFromBlocksMock([
...getBlockCallsMock(createCollectionMock().create()),
Expand All @@ -158,7 +147,7 @@ describe("rmrk2.0.0 Consolidator: LIST", () => {
const consolidator = new Consolidator();
expect(await consolidator.consolidate(remarks)).toMatchSnapshot();
});

it("Should invalidate LIST before transferable block number reached with positive transfer value", async () => {
const remarks = getRemarksFromBlocksMock([
...getBlockCallsMock(createCollectionMock().create()),
Expand All @@ -171,7 +160,7 @@ describe("rmrk2.0.0 Consolidator: LIST", () => {
"[LIST] Attempting to LIST non-transferable NFT 3-d43593c715a56da27d-KANARIABIRDS-KANR-00000777. It will become transferable after block 8 but tx made at block 4"
);
});

it("Should allow LIST after transferable block number reached with positive transfer value", async () => {
const remarks = getRemarksFromBlocksMock([
...getBlockCallsMock(createCollectionMock().create()),
Expand All @@ -181,7 +170,7 @@ describe("rmrk2.0.0 Consolidator: LIST", () => {
const consolidator = new Consolidator();
expect(await consolidator.consolidate(remarks)).toMatchSnapshot();
});

it("Should allow DE-LIST after transferable block number reached with positive transfer value", async () => {
const remarks = getRemarksFromBlocksMock([
...getBlockCallsMock(createCollectionMock().create()),
Expand Down
Loading

0 comments on commit e6be598

Please sign in to comment.