Skip to content

Commit

Permalink
test(e2e): adds test cases to nft test to assert cip0025 v1 and v2 ar…
Browse files Browse the repository at this point in the history
…e supported
  • Loading branch information
iccicci committed Feb 8, 2023
1 parent e2f3126 commit 23743b1
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts
Expand Up @@ -287,4 +287,90 @@ describe('SingleAddressWallet.assets/nft', () => {

expect(nfts.find((nft) => nft.assetId === assetIds[TOKEN_BURN_INDEX])).toBeUndefined();
});

describe('CIP-0025 v1 and v2', () => {
// eslint-disable-next-line unicorn/consistent-function-scoping
const CIP0025Test = (testName: string, assetName: string, version: 1 | 2, encoding?: 'hex' | 'utf8') =>
it(testName, async () => {
const assetNameHex = Buffer.from(assetName).toString('hex');
const assetId = Cardano.AssetId(`${policyId}${assetNameHex}`);
const fingerprint = Cardano.AssetFingerprint.fromParts(policyId, Cardano.AssetName(assetNameHex));
const tokens = new Map([[assetId, 1n]]);

const txDataMetadatum = new Map([
[
version === 1 ? policyId.toString() : Buffer.from(policyId.toString(), 'hex'),
new Map([
[
version === 1 ? (encoding === 'hex' ? assetNameHex : assetName) : Buffer.from(assetName),
metadatum.jsonToMetadatum({
image: ['ipfs://some_hash1'],
name: assetName,
version: '1.0'
})
]
])
]
]);

const auxiliaryData = { body: { blob: new Map([[721n, txDataMetadatum]]) } };

const txProps = {
auxiliaryData,
extraSigners: [policySigner],
mint: tokens,
outputs: new Set([
{
address: walletAddress,
value: {
assets: tokens,
coins: 50_000_000n
}
}
]),
scripts: [policyScript]
};

const unsignedTx = await wallet.initializeTx(txProps);

const finalizeProps = {
auxiliaryData,
extraSigners: [policySigner],
scripts: [policyScript],
tx: unsignedTx
};

const signedTx = await wallet.finalizeTx(finalizeProps);

await submitAndConfirm(wallet, signedTx);

// try remove the asset.nftMetadata filter
const nfts = await firstValueFrom(
combineLatest([wallet.assets$, wallet.balance.utxo.total$]).pipe(
filter(([assets, balance]) => assets.size === balance.assets?.size),
map(([assets]) => [...assets.values()].filter((asset) => !!asset.nftMetadata))
)
);

expect(nfts.find((nft) => nft.assetId === assetId)).toMatchObject({
assetId,
fingerprint,
mintOrBurnCount: 1,
name: assetNameHex,
nftMetadata: {
image: ['ipfs://some_hash1'],
name: assetName,
otherProperties: new Map([['version', '1.0']]),
version: '1.0'
},
policyId: policyId.toString(),
quantity: 1n,
tokenMetadata: null
});
});

CIP0025Test('supports CIP-25 v1, assetName hex encoded', 'CIP-0025-v1-hex', 1, 'hex');
CIP0025Test('supports CIP-25 v1, assetName utf8 encoded', 'CIP-0025-v1-utf8', 1, 'utf8');
CIP0025Test('supports CIP-25 v2', 'CIP-0025-v2', 2);
});
});

0 comments on commit 23743b1

Please sign in to comment.