Skip to content

Commit 4b29efd

Browse files
dominiciampogo
authored andcommitted
sdk/node: prevent v1.x params for transacting
Closes #3335 Author: Dominic Dagradi <ddagradi@gmail.com> Date: Mon Apr 16 10:44:18 2018 -0700 upstream:63da10b71a6fcb4ba7cd33a0f22fa174fb17212c
1 parent 6e970c9 commit 4b29efd

4 files changed

Lines changed: 94 additions & 11 deletions

File tree

src/api/transactions.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Client } from '../client'
22
import { Page } from '../page'
33
import { Query } from '../query'
44
import { QueryParams } from '../types'
5+
import { validate } from '../validate'
56

67
/**
78
* A blockchain consists of an immutable set of cryptographically linked
@@ -61,6 +62,7 @@ export class TransactionBuilder {
6162
tokenTags?: object
6263
actionTags?: object
6364
}) {
65+
validate(params, 'IssueActionSchema')
6466
this.actions.push(Object.assign({}, params, { type: 'issue' }))
6567
}
6668

@@ -84,6 +86,7 @@ export class TransactionBuilder {
8486
filterParams?: object
8587
actionTags?: object
8688
}) {
89+
validate(params, 'RetireActionSchema')
8790
this.actions.push(Object.assign({}, params, { type: 'retire' }))
8891
}
8992

@@ -94,6 +97,7 @@ export class TransactionBuilder {
9497
* @param {Object} params Action parameters
9598
* @param {String} params.sourceAccountId - Account ID specifying the account
9699
* controlling the flavor.
100+
* @param {String} params.flavorId - ID of flavor to be transferred.
97101
* @param {Integer} params.amount - Amount of the flavor to be transferred.
98102
* @param {String} params.destinationAccountId - Account ID specifying the
99103
* account controlling the flavor.
@@ -112,16 +116,11 @@ export class TransactionBuilder {
112116
tokenTags?: object
113117
actionTags?: object
114118
}) {
119+
validate(params, 'TransferActionSchema')
115120
this.actions.push(Object.assign({}, params, { type: 'transfer' }))
116121
}
117122
}
118123

119-
export interface TransactionQueryParameters extends QueryParams {
120-
startTime?: number
121-
endTime?: number
122-
timeout?: number
123-
}
124-
125124
/**
126125
* API for interacting with {@link Transaction transactions}.
127126
*

src/client.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import { flavorsAPI } from './api/flavors'
66
import { keysAPI } from './api/keys'
77
import { statsAPI } from './api/stats'
88
import { tokensAPI, TokenSumParams } from './api/tokens'
9-
import {
10-
TransactionBuilder,
11-
TransactionQueryParameters,
12-
transactionsAPI,
13-
} from './api/transactions'
9+
import { TransactionBuilder, transactionsAPI } from './api/transactions'
1410
import { Connection } from './connection'
1511
import { Page } from './page'
1612
import { Query } from './query'

src/validate.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,49 @@ ajv.addSchema(
6767
},
6868
'QueryParamsSchema'
6969
)
70+
71+
ajv.addSchema(
72+
{
73+
properties: {
74+
actionTags: { type: 'object' },
75+
amount: { type: 'number' },
76+
destinationAccountId: { type: 'string' },
77+
filter: { type: 'string' },
78+
filterParams: { type: 'array' },
79+
flavorId: { type: 'string' },
80+
sourceAccountId: { type: 'string' },
81+
tokenTags: { type: 'object' },
82+
},
83+
additionalProperties: false,
84+
},
85+
'TransferActionSchema'
86+
)
87+
88+
ajv.addSchema(
89+
{
90+
properties: {
91+
actionTags: { type: 'object' },
92+
amount: { type: 'number' },
93+
destinationAccountId: { type: 'string' },
94+
flavorId: { type: 'string' },
95+
tokenTags: { type: 'object' },
96+
},
97+
additionalProperties: false,
98+
},
99+
'IssueActionSchema'
100+
)
101+
102+
ajv.addSchema(
103+
{
104+
properties: {
105+
actionTags: { type: 'object' },
106+
amount: { type: 'number' },
107+
filter: { type: 'string' },
108+
filterParams: { type: 'array' },
109+
flavorId: { type: 'string' },
110+
sourceAccountId: { type: 'string' },
111+
},
112+
additionalProperties: false,
113+
},
114+
'RetireActionSchema'
115+
)

test/validateSchema.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,46 @@ describe('Schemas', () => {
105105
assert(false, 'should not accept `startTime` field')
106106
})
107107
})
108+
109+
describe('Transaction', () => {
110+
it('rejects issue with destinationAccountAlias', () => {
111+
return client.transactions.transact(builder => {
112+
builder.issue({
113+
flavorId: 'foo',
114+
amount: 1,
115+
destinationAccountAlias: 'foo',
116+
})
117+
}).then(() => assert(false, 'should not accept `destinationAccountAlias` field'))
118+
.catch(err => {
119+
expect(err.message).to.contain("should NOT have additional properties '.destinationAccountAlias'")
120+
})
121+
})
122+
123+
it('rejects transfer with destinationAccountAlias', () => {
124+
return client.transactions.transact(builder => {
125+
builder.transfer({
126+
flavorId: 'foo',
127+
amount: 1,
128+
destinationAccountAlias: 'foo',
129+
})
130+
}).then(() => assert(false, 'should not accept `destinationAccountAlias` field'))
131+
.catch(err => {
132+
expect(err.message).to.contain("should NOT have additional properties '.destinationAccountAlias'")
133+
})
134+
})
135+
136+
it('rejects retire with sourceAccountAlias', () => {
137+
return client.transactions.transact(builder => {
138+
builder.retire({
139+
flavorId: 'foo',
140+
amount: 1,
141+
sourceAccountAlias: 'foo',
142+
})
143+
}).then(() => assert(false, 'should not accept `sourceAccountAlias` field'))
144+
.catch(err => {
145+
expect(err.message).to.contain("should NOT have additional properties '.sourceAccountAlias'")
146+
})
147+
})
148+
})
149+
108150
})

0 commit comments

Comments
 (0)