AutoIncrementing.test.js 1.2 KB

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