diff --git a/contracts/erc1155/contracts/src/ERC1155.sol b/contracts/erc1155/contracts/src/ERC1155.sol index 2f1f9d4557..c4d6e38bf5 100644 --- a/contracts/erc1155/contracts/src/ERC1155.sol +++ b/contracts/erc1155/contracts/src/ERC1155.sol @@ -77,7 +77,14 @@ contract ERC1155 is // perform transfer if (isNonFungible(id)) { - require(nfOwners[id] == from); + require( + value == 1, + "AMOUNT_EQUAL_TO_ONE_REQUIRED" + ); + require( + nfOwners[id] == from, + "NFT_NOT_OWNED_BY_FROM_ADDRESS" + ); nfOwners[id] = to; // You could keep balance of NF type in base type id like so: // uint256 baseType = getNonFungibleBaseType(_id); @@ -164,7 +171,7 @@ contract ERC1155 is nfOwners[id] = to; } else { balances[id][from] = safeSub(balances[id][from], value); - balances[id][to] = safeAdd(value, balances[id][to]); + balances[id][to] = safeAdd(balances[id][to], value); } } emit TransferBatch(msg.sender, from, to, ids, values); diff --git a/contracts/erc1155/test/utils/erc1155_wrapper.ts b/contracts/erc1155/test/utils/erc1155_wrapper.ts index a7409dba07..7f620ece02 100644 --- a/contracts/erc1155/test/utils/erc1155_wrapper.ts +++ b/contracts/erc1155/test/utils/erc1155_wrapper.ts @@ -33,12 +33,13 @@ export class Erc1155Wrapper { to: string, token: BigNumber, value: BigNumber, - callbackData: string = '0x', - delegatedSpender: string = '', + callbackData?: string, + delegatedSpender?: string, ): Promise { - const spender = _.isEmpty(delegatedSpender) ? from : delegatedSpender; + const spender = _.isUndefined(delegatedSpender) ? from : delegatedSpender; + const callbackDataHex = _.isUndefined(callbackData) ? '0x' : callbackData; const tx = await this._logDecoder.getTxWithDecodedLogsAsync( - await this._erc1155Contract.safeTransferFrom.sendTransactionAsync(from, to, token, value, callbackData, { + await this._erc1155Contract.safeTransferFrom.sendTransactionAsync(from, to, token, value, callbackDataHex, { from: spender, }), ); @@ -49,17 +50,18 @@ export class Erc1155Wrapper { to: string, tokens: BigNumber[], values: BigNumber[], - callbackData: string = '0x', - delegatedSpender: string = '', + callbackData?: string, + delegatedSpender?: string, ): Promise { - const spender = _.isEmpty(delegatedSpender) ? from : delegatedSpender; + const spender = _.isUndefined(delegatedSpender) ? from : delegatedSpender; + const callbackDataHex = _.isUndefined(callbackData) ? '0x' : callbackData; const tx = await this._logDecoder.getTxWithDecodedLogsAsync( await this._erc1155Contract.safeBatchTransferFrom.sendTransactionAsync( from, to, tokens, values, - callbackData, + callbackDataHex, { from: spender }, ), );