-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction.test.ts
executable file
·40 lines (36 loc) · 1.47 KB
/
transaction.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Suite } from 'mocha';
import { helper } from '@test/helper/helper';
import { _OrdaCounter, OrdaCounterTx } from '@orda/datatypes/counter';
import { expect } from 'chai';
import { Int32 } from '@orda-io/orda-integer';
import { ErrDatatype } from '@orda/errors/datatype';
describe('Test Transaction', function (this: Suite): void {
it('Can transaction', () => {
const client = helper.getLocalClient(helper.ctName(this));
const counter = client.createCounter(helper.dtName(this));
const _counter = counter as _OrdaCounter;
expect(counter.increase(1)).to.equal(1);
Int32.enableRangeError = true;
const oldOpId = _counter.ctx.datatype!.opId.clone();
helper.L.info('before error, opId:', oldOpId.toString());
expect(() => counter.increase(Number(Int32.MAX_VALUE))).to.throw(ErrDatatype.OutOfBound);
expect(counter.get()).to.equal(1);
expect(_counter.ctx.datatype!.opId.compare(oldOpId)).to.equal(0);
counter.transaction('succeededTx', (counterTx: OrdaCounterTx) => {
counterTx.increase(2);
counterTx.increase(3);
return true;
});
expect(counter.get()).to.equal(6);
expect(() => {
counter.transaction('failedTx', (counterTx: OrdaCounterTx) => {
counterTx.increase(4);
counterTx.increase(Number(Int32.MAX_VALUE));
counterTx.increase(5);
return false;
});
}).to.throw(ErrDatatype.OutOfBound);
expect(counter.get()).to.equal(6);
Int32.enableRangeError = false;
});
});