Counter.test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const CounterImpl = artifacts.require('CounterImpl');
  2. require('../helpers/setup');
  3. const EXPECTED = [1, 2, 3, 4];
  4. const KEY1 = web3.sha3('key1');
  5. const KEY2 = web3.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. });