Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
fix: nft mint properties bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjah committed Oct 18, 2021
1 parent 0afbb57 commit cfbb608
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
15 changes: 10 additions & 5 deletions __tests__/integration/uns/certified-nft-mint-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as NftSupport from "../../functional/transaction-forging/__support__/nf
import { NFTTransactionFactory } from "../../helpers/nft-transaction-factory";
import * as Fixtures from "../../unit/uns-crypto/__fixtures__/index";
import genesisBlock from "../../utils/config/dalinet/genesisBlock.json";
import { formatProperties } from "./utils";

let walletManager: WalletManager;
let database: Database.IDatabaseService;
Expand Down Expand Up @@ -65,8 +66,8 @@ describe("certifiedNftMint handler tests for token eco v2", () => {

it("wallet bootstrap for mint transaction", async () => {
const properties = {
type: DIDTypes.INDIVIDUAL.toString(),
[LIFE_CYCLE_PROPERTY_KEY]: LifeCycleGrades.MINTED.toString(),
type: DIDTypes.INDIVIDUAL.toString(),
};
const serviceCost = Utils.BigNumber.make(654321);
const fee = 12345;
Expand Down Expand Up @@ -99,16 +100,18 @@ describe("certifiedNftMint handler tests for token eco v2", () => {

expect(Object.keys(senderWallet.getAttribute("tokens")).includes(tokenId)).toBeTrue();
expect(await nftManager.exists(tokenId)).toBeTrue();

expect(await nftRepository().findProperties(tokenId)).toEqual(formatProperties(properties));
});

it("wallet bootstrap for individual mint transaction with voucher", async () => {
const voucherId = "6trg50ZxgEPl9Av8V67c0";
const serviceCost = Utils.BigNumber.ZERO;
const fee = 0;
const properties = {
type: DIDTypes.INDIVIDUAL.toString(),
UnikVoucherId: voucherId,
[LIFE_CYCLE_PROPERTY_KEY]: LifeCycleGrades.MINTED.toString(),
UnikVoucherId: voucherId,
type: DIDTypes.INDIVIDUAL.toString(),
};
const transaction = NFTTransactionFactory.nftCertifiedMint(
tokenId,
Expand Down Expand Up @@ -138,6 +141,7 @@ describe("certifiedNftMint handler tests for token eco v2", () => {

expect(Object.keys(senderWallet.getAttribute("tokens")).includes(tokenId)).toBeTrue();
expect(await nftManager.exists(tokenId)).toBeTrue();
expect(await nftRepository().findProperties(tokenId)).toEqual(formatProperties(properties));
});

it("wallet bootstrap for organization mint transaction with voucher", async () => {
Expand All @@ -149,9 +153,9 @@ describe("certifiedNftMint handler tests for token eco v2", () => {
const fee = rewards.forger;

const properties = {
type: didType.toString(),
UnikVoucherId: voucherId,
[LIFE_CYCLE_PROPERTY_KEY]: LifeCycleGrades.MINTED.toString(),
UnikVoucherId: voucherId,
type: didType.toString(),
};
const transaction = NFTTransactionFactory.nftCertifiedMint(
tokenId,
Expand Down Expand Up @@ -180,5 +184,6 @@ describe("certifiedNftMint handler tests for token eco v2", () => {

expect(Object.keys(senderWallet.getAttribute("tokens")).includes(tokenId)).toBeTrue();
expect(await nftManager.exists(tokenId)).toBeTrue();
expect(await nftRepository().findProperties(tokenId)).toEqual(formatProperties(properties));
});
});
5 changes: 4 additions & 1 deletion __tests__/integration/uns/certified-nft-mint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as NftSupport from "../../functional/transaction-forging/__support__/nf
import { NFTTransactionFactory } from "../../helpers/nft-transaction-factory";
import * as Fixtures from "../../unit/uns-crypto/__fixtures__/index";
import genesisBlock from "../../utils/config/dalinet/genesisBlock.json";
import { formatProperties } from "./utils";

let walletManager: WalletManager;
let database: Database.IDatabaseService;
Expand Down Expand Up @@ -94,6 +95,7 @@ describe("certifiedNftMint handler tests", () => {

expect(Object.keys(senderWallet.getAttribute("tokens")).includes(tokenId)).toBeTrue();
expect(await nftManager.exists(tokenId)).toBeTrue();
expect(await nftRepository().findProperties(tokenId)).toEqual(formatProperties(properties));
});

it("wallet bootstrap for mint transaction with voucher", async () => {
Expand All @@ -103,8 +105,8 @@ describe("certifiedNftMint handler tests", () => {
const rewards = getRewardsFromDidType(didType);

const properties = {
type: didType.toString(),
UnikVoucherId: voucherId,
type: didType.toString(),
};

const transaction = NFTTransactionFactory.nftCertifiedMint(
Expand Down Expand Up @@ -135,5 +137,6 @@ describe("certifiedNftMint handler tests", () => {

expect(Object.keys(senderWallet.getAttribute("tokens")).includes(tokenId)).toBeTrue();
expect(await nftManager.exists(tokenId)).toBeTrue();
expect(await nftRepository().findProperties(tokenId)).toEqual(formatProperties(properties));
});
});
3 changes: 1 addition & 2 deletions __tests__/integration/uns/certified-nft-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as NftSupport from "../../functional/transaction-forging/__support__/nf
import { NFTTransactionFactory } from "../../helpers/nft-transaction-factory";
import * as Fixtures from "../../unit/uns-crypto/__fixtures__/index";
import genesisBlock from "../../utils/config/dalinet/genesisBlock.json";
import { formatProperties } from "./utils";

let walletManager: WalletManager;
let database: Database.IDatabaseService;
Expand Down Expand Up @@ -190,5 +191,3 @@ describe("certifiedNftupdate handler tests", () => {
expect(await nftRepo.findProperties(Fixtures.tokenId)).toEqual(formatProperties(properties));
});
});

const formatProperties = props => Object.entries(props).map(([key, val]) => ({ key, value: val }));
1 change: 1 addition & 0 deletions __tests__/integration/uns/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const formatProperties = props => Object.entries(props).map(([key, val]) => ({ key, value: val }));
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class NftMintTransactionHandler extends Handlers.TransactionHandler {

// Save changes in database
await applyNftMintDb(transaction.senderPublicKey, transaction.asset);
await applyProperties(transaction.asset);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Database, State } from "@arkecosystem/core-interfaces";
import { Handlers, Interfaces as TrxInterfaces, TransactionReader } from "@arkecosystem/core-transactions";
import { Interfaces, Managers, Transactions, Utils } from "@arkecosystem/crypto";
import { addNftToWallet, applyNftMintDb, NftMintTransactionHandler } from "@uns/core-nft";
import { addNftToWallet, applyNftMintDb, applyProperties, NftMintTransactionHandler } from "@uns/core-nft";
import { getCurrentNftAsset } from "@uns/core-nft-crypto";
import {
applyMixins,
Expand Down Expand Up @@ -57,6 +57,7 @@ export class CertifiedNftMintTransactionHandler extends NftMintTransactionHandle

// Save changes in database
await applyNftMintDb(transaction.senderPublicKey, transaction.asset);
await applyProperties(transaction.asset);
}
}
}
Expand Down

0 comments on commit cfbb608

Please sign in to comment.