Transpile 7bce2b72

This commit is contained in:
github-actions
2022-01-13 23:13:57 +00:00
commit 37c366503e
465 changed files with 80758 additions and 0 deletions

View File

@ -0,0 +1,89 @@
const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const PausableMock = artifacts.require('PausableMock');
contract('Pausable', function (accounts) {
const [ pauser ] = accounts;
beforeEach(async function () {
this.pausable = await PausableMock.new();
});
context('when unpaused', function () {
beforeEach(async function () {
expect(await this.pausable.paused()).to.equal(false);
});
it('can perform normal process in non-pause', async function () {
expect(await this.pausable.count()).to.be.bignumber.equal('0');
await this.pausable.normalProcess();
expect(await this.pausable.count()).to.be.bignumber.equal('1');
});
it('cannot take drastic measure in non-pause', async function () {
await expectRevert(this.pausable.drasticMeasure(),
'Pausable: not paused',
);
expect(await this.pausable.drasticMeasureTaken()).to.equal(false);
});
context('when paused', function () {
beforeEach(async function () {
({ logs: this.logs } = await this.pausable.pause({ from: pauser }));
});
it('emits a Paused event', function () {
expectEvent.inLogs(this.logs, 'Paused', { account: pauser });
});
it('cannot perform normal process in pause', async function () {
await expectRevert(this.pausable.normalProcess(), 'Pausable: paused');
});
it('can take a drastic measure in a pause', async function () {
await this.pausable.drasticMeasure();
expect(await this.pausable.drasticMeasureTaken()).to.equal(true);
});
it('reverts when re-pausing', async function () {
await expectRevert(this.pausable.pause(), 'Pausable: paused');
});
describe('unpausing', function () {
it('is unpausable by the pauser', async function () {
await this.pausable.unpause();
expect(await this.pausable.paused()).to.equal(false);
});
context('when unpaused', function () {
beforeEach(async function () {
({ logs: this.logs } = await this.pausable.unpause({ from: pauser }));
});
it('emits an Unpaused event', function () {
expectEvent.inLogs(this.logs, 'Unpaused', { account: pauser });
});
it('should resume allowing normal process', async function () {
expect(await this.pausable.count()).to.be.bignumber.equal('0');
await this.pausable.normalProcess();
expect(await this.pausable.count()).to.be.bignumber.equal('1');
});
it('should prevent drastic measure', async function () {
await expectRevert(this.pausable.drasticMeasure(),
'Pausable: not paused',
);
});
it('reverts when re-unpausing', async function () {
await expectRevert(this.pausable.unpause(), 'Pausable: not paused');
});
});
});
});
});
});

View File

@ -0,0 +1,51 @@
const { balance, ether } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const PullPaymentMock = artifacts.require('PullPaymentMock');
contract('PullPayment', function (accounts) {
const [ payer, payee1, payee2 ] = accounts;
const amount = ether('17');
beforeEach(async function () {
this.contract = await PullPaymentMock.new({ value: amount });
});
describe('payments', function () {
it('can record an async payment correctly', async function () {
await this.contract.callTransfer(payee1, 100, { from: payer });
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('100');
});
it('can add multiple balances on one account', async function () {
await this.contract.callTransfer(payee1, 200, { from: payer });
await this.contract.callTransfer(payee1, 300, { from: payer });
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('500');
});
it('can add balances on multiple accounts', async function () {
await this.contract.callTransfer(payee1, 200, { from: payer });
await this.contract.callTransfer(payee2, 300, { from: payer });
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('200');
expect(await this.contract.payments(payee2)).to.be.bignumber.equal('300');
});
});
describe('withdrawPayments', function () {
it('can withdraw payment', async function () {
const balanceTracker = await balance.tracker(payee1);
await this.contract.callTransfer(payee1, amount, { from: payer });
expect(await this.contract.payments(payee1)).to.be.bignumber.equal(amount);
await this.contract.withdrawPayments(payee1);
expect(await balanceTracker.delta()).to.be.bignumber.equal(amount);
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('0');
});
});
});

View File

@ -0,0 +1,40 @@
const { expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ReentrancyMock = artifacts.require('ReentrancyMock');
const ReentrancyAttack = artifacts.require('ReentrancyAttack');
contract('ReentrancyGuard', function (accounts) {
beforeEach(async function () {
this.reentrancyMock = await ReentrancyMock.new();
expect(await this.reentrancyMock.counter()).to.be.bignumber.equal('0');
});
it('nonReentrant function can be called', async function () {
expect(await this.reentrancyMock.counter()).to.be.bignumber.equal('0');
await this.reentrancyMock.callback();
expect(await this.reentrancyMock.counter()).to.be.bignumber.equal('1');
});
it('does not allow remote callback', async function () {
const attacker = await ReentrancyAttack.new();
await expectRevert(
this.reentrancyMock.countAndCall(attacker.address), 'ReentrancyAttack: failed call');
});
// The following are more side-effects than intended behavior:
// I put them here as documentation, and to monitor any changes
// in the side-effects.
it('does not allow local recursion', async function () {
await expectRevert(
this.reentrancyMock.countLocalRecursive(10), 'ReentrancyGuard: reentrant call',
);
});
it('does not allow indirect local recursion', async function () {
await expectRevert(
this.reentrancyMock.countThisRecursive(10), 'ReentrancyMock: failed call',
);
});
});