Skip to content

Commit

Permalink
Allow spaces in nft names when sending NFT to NFT. closes #125
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuripetusko committed Apr 14, 2023
1 parent 6f1b1d4 commit 80b4406
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 267 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.21.0",
"@pinata/sdk": "^1.1.13",
"@polkadot/api": "^10.0.1",
"@polkadot/keyring": "^11.0.1",
"@polkadot/util-crypto": "^11.0.1",
"@polkadot/x-randomvalues": "^11.0.1",
"@polkadot/api": "^10.3.2",
"@polkadot/keyring": "^11.1.3",
"@polkadot/util-crypto": "^11.1.3",
"@polkadot/x-randomvalues": "^11.1.3",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
Expand Down Expand Up @@ -89,7 +89,7 @@
"webpack-cli": "^4.5.0"
},
"dependencies": {
"@polkadot/api-augment": "^10.0.1",
"@polkadot/api-augment": "^10.3.2",
"JSONStream": "^1.3.5",
"chalk": "^4.1.0",
"emoji-regex": "^9.2.2",
Expand Down
3 changes: 2 additions & 1 deletion src/rmrk2.0.0/tools/validate-remark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getRemarkData } from "./utils";
import { collectionRegexPattern } from "../classes/equippable";
import { PropertiesStruct } from "./validate-metadata";
import { IProperties, IRoyaltyAttribute } from "./types";
import {isValidAddressPolkadotAddress} from "./consolidator/utils";

const PartStruct = type({
type: enums(["slot", "fixed"]),
Expand Down Expand Up @@ -306,7 +307,7 @@ export const validateSend = (remark: string): any => {

try {
validateRemarkBase(remark, OP_TYPES.SEND);
if (/\s/g.test(recipient)) {
if (isValidAddressPolkadotAddress(recipient) && /\s/g.test(recipient)) {
throw new Error(
"Invalid remark - No whitespaces are allowed in recipient"
);
Expand Down
23 changes: 23 additions & 0 deletions test/2.0.0/consolidator/send.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Consolidator } from "../../../src/rmrk2.0.0";
import {
createCollectionMock,
createCollectionMock2,
createCollectionMock3,
getBlockCallsMock,
getBobKey,
getRemarksFromBlocksMock,
mintNftMock,
mintNftMock2,
mintNftMock3,
mintNftMock4,
} from "../mocks";
import { cryptoWaitReady } from "@polkadot/util-crypto";

Expand Down Expand Up @@ -223,4 +225,25 @@ describe("rmrk2.0.0 Consolidator: Send NFT to other NFT", () => {
const consolidator = new Consolidator();
expect(await consolidator.consolidate(remarks)).toMatchSnapshot();
});

it("Should allow SEND if collection id has space", async () => {
const remarks = getRemarksFromBlocksMock([
...getBlockCallsMock(createCollectionMock3().create()),
...getBlockCallsMock(mintNftMock3(0, createCollectionMock3(0).id).mint()),
...getBlockCallsMock(mintNftMock4(0, createCollectionMock3(0).id).mint()),
...getBlockCallsMock(
mintNftMock4(4, createCollectionMock3(0).id).send(
mintNftMock4(3, createCollectionMock3(0).id).getId()
)
),
]);

const consolidator = new Consolidator();
const consolidatedResult = await consolidator.consolidate(remarks);

const nft = Object.values(consolidatedResult.nfts)[1];
expect(nft.owner).toEqual(
mintNftMock4(3, createCollectionMock3(0).id).getId()
);
});
});
33 changes: 30 additions & 3 deletions test/2.0.0/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getRemarksFromBlocks, NFT, Collection } from "../../src/rmrk2.0.0";
import { stringToHex, u8aToHex } from "@polkadot/util";
import { stringToHex, u8aToHex, stringToU8a } from "@polkadot/util";
import { Remark } from "../../src/rmrk2.0.0/tools/consolidator/remark";
import { Block } from "../../src/rmrk2.0.0/tools/utils";
import { encodeAddress, Keyring } from "@polkadot/keyring";
import { Keyring } from "@polkadot/keyring";
import { Base } from "../../src/rmrk2.0.0/classes/base";
import { OP_TYPES } from "../../src/rmrk2.0.0/tools/constants";
import { BlockCall } from "../../src/rmrk2.0.0/tools/types";
Expand Down Expand Up @@ -31,7 +31,7 @@ export const createCollectionMock = (
address || getAliceKey().address,
"KANARIABIRDS",
Collection.generateId(
u8aToHex(address || getAliceKey().publicKey),
u8aToHex(address ? stringToU8a(address) : getAliceKey().publicKey),
"KANARIABIRDS"
),
"https://some.url"
Expand All @@ -55,6 +55,23 @@ export const createCollectionMock2 = (
);
};

export const createCollectionMock3 = (
block?: number,
keyring?: KeyringPair
): Collection => {
return new Collection(
block || 0,
0,
keyring?.address || getAliceKey().address,
"GAMMA GANG",
Collection.generateId(
u8aToHex(keyring?.publicKey || getAliceKey().publicKey),
"GAMMA GANG"
),
"https://some.url"
);
};

export const mintNftMock = (
block?: number,
nftInstanceProps?: Partial<INftInstanceProps>
Expand Down Expand Up @@ -93,6 +110,16 @@ export const mintNftMock3 = (block?: number, collectionId?: string): NFT =>
owner: getBobKey().address,
});

export const mintNftMock4 = (block?: number, collectionId?: string): NFT =>
new NFT({
block: block || 0,
collection: collectionId || createCollectionMock3().id,
symbol: "KANR",
sn: "999".padStart(8, "0"),
transferable: 1,
owner: getBobKey().address,
});

export const createBaseMock = (block?: number): Base =>
new Base(
block || 0,
Expand Down
Loading

0 comments on commit 80b4406

Please sign in to comment.