AutoIncrementing.test.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const { hashMessage } = require('./helpers/sign');
  2. const AutoIncrementing = artifacts.require('AutoIncrementingImpl');
  3. require('chai')
  4. .use(require('chai-bignumber')(web3.BigNumber))
  5. .should();
  6. const EXPECTED = [1, 2, 3, 4];
  7. const KEY1 = hashMessage('key1');
  8. const KEY2 = hashMessage('key2');
  9. contract('AutoIncrementing', function ([_, owner]) {
  10. beforeEach(async function () {
  11. this.mock = await AutoIncrementing.new({ from: owner });
  12. });
  13. context('custom key', async function () {
  14. it('should return expected values', async function () {
  15. for (const expectedId of EXPECTED) {
  16. await this.mock.doThing(KEY1, { from: owner });
  17. const actualId = await this.mock.theId();
  18. actualId.should.be.bignumber.equal(expectedId);
  19. }
  20. });
  21. });
  22. context('parallel keys', async function () {
  23. it('should return expected values for each counter', async function () {
  24. for (const expectedId of EXPECTED) {
  25. await this.mock.doThing(KEY1, { from: owner });
  26. let actualId = await this.mock.theId();
  27. actualId.should.be.bignumber.equal(expectedId);
  28. await this.mock.doThing(KEY2, { from: owner });
  29. actualId = await this.mock.theId();
  30. actualId.should.be.bignumber.equal(expectedId);
  31. }
  32. });
  33. });
  34. });