tests for allowance approvals on erc1155

This commit is contained in:
Greg Hysen
2019-02-28 11:00:21 -08:00
parent a1c121e2fe
commit 60d24ada62
4 changed files with 141 additions and 11 deletions

View File

@@ -32,10 +32,12 @@ export class Erc1155Wrapper {
token: BigNumber,
value: BigNumber,
callbackData: string = '0x',
delegatedSpender: string = '',
): Promise<TransactionReceiptWithDecodedLogs> {
const spender = _.isEmpty(delegatedSpender) ? from : delegatedSpender;
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(
await this._erc1155Contract.safeTransferFrom.sendTransactionAsync(from, to, token, value, callbackData, {
from,
from: spender,
}),
);
return tx;
@@ -46,7 +48,9 @@ export class Erc1155Wrapper {
tokens: BigNumber[],
values: BigNumber[],
callbackData: string = '0x',
delegatedSpender: string = '',
): Promise<TransactionReceiptWithDecodedLogs> {
const spender = _.isEmpty(delegatedSpender) ? from : delegatedSpender;
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(
await this._erc1155Contract.safeBatchTransferFrom.sendTransactionAsync(
from,
@@ -54,7 +58,7 @@ export class Erc1155Wrapper {
tokens,
values,
callbackData,
{ from },
{ from: spender },
),
);
return tx;
@@ -98,6 +102,22 @@ export class Erc1155Wrapper {
const nftId = token.plus(1);
return [token, nftId];
}
public async setApprovalForAllAsync(
owner: string,
beneficiary: string,
isApproved: boolean,
): Promise<TransactionReceiptWithDecodedLogs> {
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(
await this._erc1155Contract.setApprovalForAll.sendTransactionAsync(beneficiary, isApproved, {
from: owner,
}),
);
return tx;
}
public async isApprovedForAllAsync(owner: string, beneficiary: string): Promise<boolean> {
const isApprovedForAll = await this._erc1155Contract.isApprovedForAll.callAsync(owner, beneficiary);
return isApprovedForAll;
}
public async assertBalancesAsync(
owners: string[],
tokens: BigNumber[],