Skip to content

Commit c5287b9

Browse files
dominiciampogo
authored andcommitted
sdk/node: throw validation error for large integers
Closes #3604 Author: Dominic Dagradi <ddagradi@gmail.com> Date: Sun May 6 14:26:29 2018 -0700 upstream:b9816a2764f3cafce9da2577d3f08abd2f2d73e3
1 parent d58f502 commit c5287b9

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

src/validate.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ ajv.addSchema(
7373
properties: {
7474
actionTags: { type: 'object' },
7575
amount: {
76-
anyOf: [{ type: 'number' }, { type: 'object' }],
76+
anyOf: [
77+
{
78+
type: 'number',
79+
minimum: 0,
80+
maximum: Number.MAX_SAFE_INTEGER,
81+
},
82+
{ type: 'object' },
83+
],
7784
},
7885
destinationAccountId: { type: 'string' },
7986
filter: { type: 'string' },
@@ -92,7 +99,14 @@ ajv.addSchema(
9299
properties: {
93100
actionTags: { type: 'object' },
94101
amount: {
95-
anyOf: [{ type: 'number' }, { type: 'object' }],
102+
anyOf: [
103+
{
104+
type: 'number',
105+
minimum: 0,
106+
maximum: Number.MAX_SAFE_INTEGER,
107+
},
108+
{ type: 'object' },
109+
],
96110
},
97111
destinationAccountId: { type: 'string' },
98112
flavorId: { type: 'string' },
@@ -108,7 +122,14 @@ ajv.addSchema(
108122
properties: {
109123
actionTags: { type: 'object' },
110124
amount: {
111-
anyOf: [{ type: 'number' }, { type: 'object' }],
125+
anyOf: [
126+
{
127+
type: 'number',
128+
minimum: 0,
129+
maximum: Number.MAX_SAFE_INTEGER,
130+
},
131+
{ type: 'object' },
132+
],
112133
},
113134
filter: { type: 'string' },
114135
filterParams: { type: 'array' },

test/transactions.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('Transaction', () => {
9696
const alice = await createAccount('alice')
9797
const amount = '9223372036854775808'
9898

99-
expect(
99+
return expect(
100100
client.transactions.transact(builder => {
101101
builder.issue({
102102
flavorId: gold.id,
@@ -106,6 +106,22 @@ describe('Transaction', () => {
106106
})
107107
).to.be.rejectedWith('SEQ706')
108108
})
109+
110+
it('throws an error when losing precision', async () => {
111+
const gold = await createFlavor('gold')
112+
const alice = await createAccount('alice')
113+
const amount = 9999999999999999
114+
115+
return expect(
116+
client.transactions.transact(builder => {
117+
builder.issue({
118+
flavorId: gold.id,
119+
amount,
120+
destinationAccountId: alice.id,
121+
})
122+
})
123+
).to.be.rejectedWith('should be <= 9007199254740991')
124+
})
109125
})
110126

111127
describe('Transfer', () => {

0 commit comments

Comments
 (0)