Counter.test.js 1.2 KB

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