Draft EIP 1820 (#1677)
* Add barebones EIP1820 support. * Update openzeppelin-test-helpers dependency to have ERC1820 support. * Add tests for ERC1820. * Improve inline documentation. * Add changelog entry. * Update test-helpers, refactor tests to use new helpers. * Rename ERC1820 to ERC1820Implementer. * Improve implementer docstring. * Remove _implementsInterfaceForAddress. * update openzeppelin-test-helpers to 0.2.0 * Update contracts/drafts/ERC1820Implementer.sol Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Fix how solidity coverage is run to allow for free events. * Fix coverage testing script.
This commit is contained in:
@ -47,9 +47,9 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
|
||||
});
|
||||
|
||||
it('should forward funds to wallet', async function () {
|
||||
(await balance.difference(wallet, () =>
|
||||
this.crowdsale.sendTransaction({ value, from: investor }))
|
||||
).should.be.bignumber.equal(value);
|
||||
const balanceTracker = await balance.tracker(wallet);
|
||||
await this.crowdsale.sendTransaction({ value, from: investor });
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(value);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -88,9 +88,9 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
|
||||
});
|
||||
|
||||
it('should forward funds to wallet', async function () {
|
||||
(await balance.difference(wallet, () =>
|
||||
this.crowdsale.sendTransaction({ value, from: investor }))
|
||||
).should.be.bignumber.equal(value);
|
||||
const balanceTracker = await balance.tracker(wallet);
|
||||
await this.crowdsale.sendTransaction({ value, from: investor });
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(value);
|
||||
});
|
||||
});
|
||||
|
||||
@ -111,9 +111,9 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
|
||||
});
|
||||
|
||||
it('should forward funds to wallet', async function () {
|
||||
(await balance.difference(wallet, () =>
|
||||
this.crowdsale.buyTokens(investor, { value, from: purchaser }))
|
||||
).should.be.bignumber.equal(value);
|
||||
const balanceTracker = await balance.tracker(wallet);
|
||||
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(value);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -28,9 +28,9 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate
|
||||
});
|
||||
|
||||
it('should forward funds to wallet', async function () {
|
||||
(await balance.difference(wallet, () =>
|
||||
this.crowdsale.sendTransaction({ value, from: investor }))
|
||||
).should.be.bignumber.equal(value);
|
||||
const balanceTracker = await balance.tracker(wallet);
|
||||
await this.crowdsale.sendTransaction({ value, from: investor });
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(value);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -65,9 +65,9 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon
|
||||
});
|
||||
|
||||
it('refunds', async function () {
|
||||
(await balance.difference(investor, () =>
|
||||
this.crowdsale.claimRefund(investor, { gasPrice: 0 }))
|
||||
).should.be.bignumber.equal(lessThanGoal);
|
||||
const balanceTracker = await balance.tracker(investor);
|
||||
await this.crowdsale.claimRefund(investor, { gasPrice: 0 });
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(lessThanGoal);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
61
test/drafts/ERC1820Implementer.test.js
Normal file
61
test/drafts/ERC1820Implementer.test.js
Normal file
@ -0,0 +1,61 @@
|
||||
const { shouldFail, singletons } = require('openzeppelin-test-helpers');
|
||||
const { bufferToHex, keccak256 } = require('ethereumjs-util');
|
||||
|
||||
const ERC1820ImplementerMock = artifacts.require('ERC1820ImplementerMock');
|
||||
|
||||
contract('ERC1820Implementer', function ([_, registryFunder, implementee, anyone]) {
|
||||
const ERC1820_ACCEPT_MAGIC = bufferToHex(keccak256('ERC1820_ACCEPT_MAGIC'));
|
||||
|
||||
beforeEach(async function () {
|
||||
this.implementer = await ERC1820ImplementerMock.new();
|
||||
this.registry = await singletons.ERC1820Registry(registryFunder);
|
||||
|
||||
this.interfaceA = bufferToHex(keccak256('interfaceA'));
|
||||
this.interfaceB = bufferToHex(keccak256('interfaceB'));
|
||||
});
|
||||
|
||||
context('with no registered interfaces', function () {
|
||||
it('returns false when interface implementation is queried', async function () {
|
||||
(await this.implementer.canImplementInterfaceForAddress(this.interfaceA, implementee))
|
||||
.should.not.equal(ERC1820_ACCEPT_MAGIC);
|
||||
});
|
||||
|
||||
it('reverts when attempting to set as implementer in the registry', async function () {
|
||||
await shouldFail.reverting(
|
||||
this.registry.setInterfaceImplementer(
|
||||
implementee, this.interfaceA, this.implementer.address, { from: implementee }
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
context('with registered interfaces', function () {
|
||||
beforeEach(async function () {
|
||||
await this.implementer.registerInterfaceForAddress(this.interfaceA, implementee);
|
||||
});
|
||||
|
||||
it('returns true when interface implementation is queried', async function () {
|
||||
(await this.implementer.canImplementInterfaceForAddress(this.interfaceA, implementee))
|
||||
.should.equal(ERC1820_ACCEPT_MAGIC);
|
||||
});
|
||||
|
||||
it('returns false when interface implementation for non-supported interfaces is queried', async function () {
|
||||
(await this.implementer.canImplementInterfaceForAddress(this.interfaceB, implementee))
|
||||
.should.not.equal(ERC1820_ACCEPT_MAGIC);
|
||||
});
|
||||
|
||||
it('returns false when interface implementation for non-supported addresses is queried', async function () {
|
||||
(await this.implementer.canImplementInterfaceForAddress(this.interfaceA, anyone))
|
||||
.should.not.equal(ERC1820_ACCEPT_MAGIC);
|
||||
});
|
||||
|
||||
it('can be set as an implementer for supported interfaces in the registry', async function () {
|
||||
await this.registry.setInterfaceImplementer(
|
||||
implementee, this.interfaceA, this.implementer.address, { from: implementee }
|
||||
);
|
||||
|
||||
(await this.registry.getInterfaceImplementer(implementee, this.interfaceA))
|
||||
.should.equal(this.implementer.address);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -72,21 +72,23 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
|
||||
await time.increaseTo(this.openingTime);
|
||||
await this.crowdsale.send(GOAL);
|
||||
|
||||
(await balance.difference(wallet, async () => {
|
||||
await time.increaseTo(this.afterClosingTime);
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
})).should.be.bignumber.equal(GOAL);
|
||||
const balanceTracker = await balance.tracker(wallet);
|
||||
await time.increaseTo(this.afterClosingTime);
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(GOAL);
|
||||
});
|
||||
|
||||
it('should allow refunds if the goal is not reached', async function () {
|
||||
(await balance.difference(investor, async () => {
|
||||
await time.increaseTo(this.openingTime);
|
||||
await this.crowdsale.sendTransaction({ value: ether('1'), from: investor, gasPrice: 0 });
|
||||
await time.increaseTo(this.afterClosingTime);
|
||||
const balanceTracker = await balance.tracker(investor);
|
||||
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
await this.crowdsale.claimRefund(investor, { gasPrice: 0 });
|
||||
})).should.be.bignumber.equal('0');
|
||||
await time.increaseTo(this.openingTime);
|
||||
await this.crowdsale.sendTransaction({ value: ether('1'), from: investor, gasPrice: 0 });
|
||||
await time.increaseTo(this.afterClosingTime);
|
||||
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
await this.crowdsale.claimRefund(investor, { gasPrice: 0 });
|
||||
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal('0');
|
||||
});
|
||||
|
||||
describe('when goal > cap', function () {
|
||||
|
||||
@ -30,13 +30,14 @@ contract('PullPayment', function ([_, payer, payee1, payee2]) {
|
||||
});
|
||||
|
||||
it('can withdraw payment', async function () {
|
||||
(await balance.difference(payee1, async () => {
|
||||
await this.contract.callTransfer(payee1, amount, { from: payer });
|
||||
(await this.contract.payments(payee1)).should.be.bignumber.equal(amount);
|
||||
const balanceTracker = await balance.tracker(payee1);
|
||||
|
||||
await this.contract.withdrawPayments(payee1);
|
||||
})).should.be.bignumber.equal(amount);
|
||||
await this.contract.callTransfer(payee1, amount, { from: payer });
|
||||
(await this.contract.payments(payee1)).should.be.bignumber.equal(amount);
|
||||
|
||||
await this.contract.withdrawPayments(payee1);
|
||||
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(amount);
|
||||
(await this.contract.payments(payee1)).should.be.bignumber.equal('0');
|
||||
});
|
||||
});
|
||||
|
||||
@ -52,10 +52,12 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
|
||||
|
||||
describe('withdrawals', async function () {
|
||||
it('can withdraw payments', async function () {
|
||||
(await balance.difference(payee1, async () => {
|
||||
await this.escrow.deposit(payee1, { from: primary, value: amount });
|
||||
await this.escrow.withdraw(payee1, { from: primary });
|
||||
})).should.be.bignumber.equal(amount);
|
||||
const balanceTracker = await balance.tracker(payee1);
|
||||
|
||||
await this.escrow.deposit(payee1, { from: primary, value: amount });
|
||||
await this.escrow.withdraw(payee1, { from: primary });
|
||||
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(amount);
|
||||
|
||||
(await balance.current(this.escrow.address)).should.be.bignumber.equal('0');
|
||||
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal('0');
|
||||
|
||||
@ -64,9 +64,9 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
|
||||
});
|
||||
|
||||
it('allows beneficiary withdrawal', async function () {
|
||||
(await balance.difference(beneficiary, () =>
|
||||
this.escrow.beneficiaryWithdraw()
|
||||
)).should.be.bignumber.equal(amount.muln(refundees.length));
|
||||
const balanceTracker = await balance.tracker(beneficiary);
|
||||
await this.escrow.beneficiaryWithdraw();
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(amount.muln(refundees.length));
|
||||
});
|
||||
|
||||
it('prevents entering the refund state', async function () {
|
||||
@ -98,9 +98,9 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
|
||||
|
||||
it('refunds refundees', async function () {
|
||||
for (const refundee of [refundee1, refundee2]) {
|
||||
(await balance.difference(refundee, () =>
|
||||
this.escrow.withdraw(refundee, { from: primary }))
|
||||
).should.be.bignumber.equal(amount);
|
||||
const balanceTracker = await balance.tracker(refundee);
|
||||
await this.escrow.withdraw(refundee, { from: primary });
|
||||
(await balanceTracker.delta()).should.be.bignumber.equal(amount);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user