Skip to content
Closed

ERC1363 #3017

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add changeset and update to hardat-expose
  • Loading branch information
Amxx committed Feb 23, 2023
commit 7e2bbfdb53234d46f645e044eefc22a0d437a780
5 changes: 5 additions & 0 deletions .changeset/tasty-apples-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`ERC1363`: Add an extension to `ERC20` for performing transferAndCall & approveAndCall operations following ERC-1363.
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,8 @@

pragma solidity ^0.8.0;

import "../token/ERC20/extensions/ERC1363.sol";

contract ERC1363Mock is ERC1363 {
constructor(
string memory name,
string memory symbol,
address initialAccount,
uint256 initialBalance
) payable ERC20(name, symbol) {
_mint(initialAccount, initialBalance);
}

function mint(address account, uint256 amount) public {
_mint(account, amount);
}

function burn(address account, uint256 amount) public {
_burn(account, amount);
}
}
import "../../interfaces/IERC1363Receiver.sol";
import "../../interfaces/IERC1363Spender.sol";

contract ERC1363ReceiverMock is IERC1363Receiver, IERC1363Spender {
event TransferReceived(address operator, address from, uint256 value, bytes data);
Expand Down Expand Up @@ -57,4 +39,4 @@ contract ERC1363ReceiverMock is IERC1363Receiver, IERC1363Spender {
emit ApprovalReceived(owner, value, data);
return this.onApprovalReceived.selector;
}
}
}
15 changes: 8 additions & 7 deletions test/token/ERC20/extensions/ERC1363.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { shouldSupportInterfaces } = require('../../../utils/introspection/SupportsInterface.behavior');

const ERC1363Mock = artifacts.require('ERC1363Mock');
const ERC1363Mock = artifacts.require('$ERC1363');
const ERC1363ReceiverMock = artifacts.require('ERC1363ReceiverMock');

contract('ERC1363', function (accounts) {
const [ holder, operator, other ] = accounts;

const initialSupply = new BN(100);
const value = new BN(10);

const name = 'My Token';
const symbol = 'MTKN';
const supply = web3.utils.toBN(100);
const value = web3.utils.toBN(10);

beforeEach(async function () {
this.token = await ERC1363Mock.new(name, symbol, holder, initialSupply);
this.token = await ERC1363Mock.new(name, symbol);
this.receiver = await ERC1363ReceiverMock.new();

await this.token.$_mint(holder, supply);
});

shouldSupportInterfaces([
Expand Down Expand Up @@ -105,7 +106,7 @@ contract('ERC1363', function (accounts) {

describe('transferFromAndCall', function () {
beforeEach(async function () {
await this.token.approve(operator, initialSupply, { from: holder });
await this.token.approve(operator, supply, { from: holder });
});

it('to EOA', async function () {
Expand Down