Skip to content

Commit 3cd059a

Browse files
authored
fetchEvaluate (#57)
1 parent eec2a43 commit 3cd059a

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api-node/utils/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ export function fetchEstimate(base: string, body: string): Promise<IEstimate> {
6868
})
6969
}
7070

71+
/**
72+
* POST /utils/script/evaluate
73+
* Evaluates the provided expression, taking into account the deployed dApp contract
74+
*/
75+
export function fetchEvaluate(base: string, address: string, expr: string): Promise<IEvaluate> {
76+
return request({
77+
base,
78+
url: `/utils/script/evaluate/${address}`,
79+
options: {
80+
method: 'POST',
81+
body: JSON.stringify({ expr }),
82+
headers: {
83+
'Content-Type': 'application/json'
84+
}
85+
}
86+
})
87+
}
88+
7189
/**
7290
* POST /utils/transactionSerialize
7391
* Serialize transaction
@@ -213,6 +231,13 @@ export interface IEstimate extends ICompileCode {
213231
scriptText: string;
214232
}
215233

234+
export interface IEvaluate {
235+
address: string;
236+
expr: string;
237+
result: object;
238+
complexity: number;
239+
}
240+
216241
interface ICompileWithImportsBody {
217242
script: string;
218243
imports: object;

test/api-node/utils.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ it('decompile code', async () => {
2929
expect(typeof decompiled.script).toBe('string');
3030
});
3131

32+
it('evaluate', async () => {
33+
const targetAddress = STATE.ACCOUNTS.FOR_SCRIPT.address;
34+
const expr = 'call()';
35+
const response = await api.utils.fetchEvaluate(targetAddress, expr);
36+
expect(response.address).toEqual(targetAddress);
37+
expect(response.complexity).toEqual(1);
38+
expect(response.expr).toEqual(expr);
39+
expect(response.result).toEqual({ type: 'Array', value: [] });
40+
});
41+
3242
it('time', async () => {
3343
const nodeTime = await api.utils.fetchNodeTime();
3444
expect(typeof nodeTime.NTP).toBe('number');

0 commit comments

Comments
 (0)