From 2b024070c7b0029a51d7fb339f937ec2d94ec4e8 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 08 Feb 2021 13:38:09 +0000 Subject: [PATCH] tests: contract whitelist helpers --- --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -424,6 +424,54 @@ }); } +export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enabled: boolean) { + await usingApi(async (api) => { + const tx = api.tx.nft.toggleContractWhiteList(contractAddress, true); + const events = await submitTransactionAsync(sender, tx); + const result = getGenericResult(events); + + expect(result.success).to.be.true; + }); +} + +export async function isWhitelistedInContract(contractAddress: AccountId | string, user: string) { + let whitelisted: boolean = false; + await usingApi(async (api) => { + whitelisted = (await api.query.nft.contractWhiteList(contractAddress, user)).toJSON() as boolean; + }); + return whitelisted; +} + +export async function addToContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: string) { + await usingApi(async (api) => { + const tx = api.tx.nft.addToContractWhiteList(contractAddress, user); + const events = await submitTransactionAsync(sender, tx); + const result = getGenericResult(events); + + expect(result.success).to.be.true; + }); +} + +export async function removeFromContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: string) { + await usingApi(async (api) => { + const tx = api.tx.nft.removeFromContractWhiteList(contractAddress, user); + const events = await submitTransactionAsync(sender, tx); + const result = getGenericResult(events); + + expect(result.success).to.be.true; + }); +} + +export async function removeFromContractWhiteListExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, user: string) { + await usingApi(async (api) => { + const tx = api.tx.nft.removeFromContractWhiteList(contractAddress, user); + const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected; + const result = getGenericResult(events); + + expect(result.success).to.be.false; + }); +} + export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) { await usingApi(async (api) => { const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex')); -- gitstuff