Nonces.test.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const expectEvent = require('@openzeppelin/test-helpers/src/expectEvent');
  2. require('@openzeppelin/test-helpers');
  3. const Nonces = artifacts.require('$Nonces');
  4. contract('Nonces', function (accounts) {
  5. const [sender, other] = accounts;
  6. beforeEach(async function () {
  7. this.nonces = await Nonces.new();
  8. });
  9. it('gets a nonce', async function () {
  10. expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('0');
  11. });
  12. it('increment a nonce', async function () {
  13. expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('0');
  14. const { receipt } = await this.nonces.$_useNonce(sender);
  15. expectEvent(receipt, 'return$_useNonce', ['0']);
  16. expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('1');
  17. });
  18. it('nonce is specific to address argument', async function () {
  19. expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('0');
  20. expect(await this.nonces.nonces(other)).to.be.bignumber.equal('0');
  21. await this.nonces.$_useNonce(sender);
  22. expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('1');
  23. expect(await this.nonces.nonces(other)).to.be.bignumber.equal('0');
  24. });
  25. });