Sure… it’s straight from the Simple ERC777 token example
I don’t believe I changed anything…
Simple777Token.test.js
const { expectEvent, singletons, constants, BN } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const Simple777Token = artifacts.require('Simple777Token');
contract('Simple777Token', function ([_, registryFunder, creator, operator]) {
beforeEach(async function () {
this.erc1820 = await singletons.ERC1820Registry(registryFunder);
this.token = await Simple777Token.new({ from: creator });
});
it('has a name', async function () {
(await this.token.name()).should.equal('Simple777Token');
});
it('has a symbol', async function () {
(await this.token.symbol()).should.equal('S7');
});
it('assigns the initial total supply to the creator', async function () {
const totalSupply = await this.token.totalSupply();
const creatorBalance = await this.token.balanceOf(creator);
creatorBalance.should.be.bignumber.equal(totalSupply);
await expectEvent.inConstruction(this.token, 'Transfer', {
from: ZERO_ADDRESS,
to: creator,
value: totalSupply,
});
});
it('allows operator burn', async function () {
const creatorBalance = await this.token.balanceOf(creator);
const data = web3.utils.sha3('Simple777Data');
const operatorData = web3.utils.sha3('Simple777OperatorData');
await this.token.authorizeOperator(operator, { from: creator });
await this.token.operatorBurn(creator, creatorBalance, data, operatorData, { from: operator });
(await this.token.balanceOf(creator)).should.be.bignumber.equal("0");
});
});
Simple777Recipient.test.js
const { singletons, BN, expectEvent } = require('@openzeppelin/test-helpers');
const Simple777Token = artifacts.require('Simple777Token');
const Simple777Recipient = artifacts.require('Simple777Recipient');
contract('Simple777Recipient', function ([_, registryFunder, creator, holder]) {
const data = web3.utils.sha3('777TestData');
beforeEach(async function () {
this.erc1820 = await singletons.ERC1820Registry(registryFunder);
this.token = await Simple777Token.new({ from: creator });
const amount = new BN(10000);
await this.token.send(holder, amount, data, { from: creator });
this.recipient = await Simple777Recipient.new(this.token.address, { from: creator });
});
it('sends to a contract from an externally-owned account', async function () {
const amount = new BN(1000);
const receipt = await this.token.send(this.recipient.address, amount, data, { from: holder });
await expectEvent.inTransaction(receipt.tx, Simple777Recipient, 'DoneStuff', { from: holder, to: this.recipient.address, amount: amount, userData: data, operatorData: null });
const recipientBalance = await this.token.balanceOf(this.recipient.address);
recipientBalance.should.be.bignumber.equal(amount);
});
});
Simple777Sender.test.js
const { singletons, BN, expectEvent } = require('@openzeppelin/test-helpers');
const Simple777Token = artifacts.require('Simple777Token');
const Simple777Sender = artifacts.require('Simple777Sender');
contract('Simple777Sender', function ([_, registryFunder, creator, holder, recipient]) {
const data = web3.utils.sha3('777TestData');
beforeEach(async function () {
this.erc1820 = await singletons.ERC1820Registry(registryFunder);
this.token = await Simple777Token.new({ from: creator });
const amount = new BN(10000);
await this.token.send(holder, amount, data, { from: creator });
this.sender = await Simple777Sender.new({ from: creator });
});
it('sends from an externally-owned account', async function () {
const amount = new BN(1000);
const tokensSenderInterfaceHash = await this.sender.TOKENS_SENDER_INTERFACE_HASH();
await this.sender.senderFor(holder);
await this.erc1820.setInterfaceImplementer(holder, tokensSenderInterfaceHash, this.sender.address, { from: holder });
const receipt = await this.token.send(recipient, amount, data, { from: holder });
await expectEvent.inTransaction(receipt.tx, Simple777Sender, 'DoneStuff', { from: holder, to: recipient, amount: amount, userData: data, operatorData: null });
const recipientBalance = await this.token.balanceOf(recipient);
recipientBalance.should.be.bignumber.equal(amount);
});
});