Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rpc): fix invokescript method #2216

Merged
merged 1 commit into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/neo-one-client-common/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export interface NotificationJSON {
export interface CallReceiptJSON {
readonly script: string;
readonly state: keyof typeof VMState;
readonly gasconsumed: number;
readonly gasconsumed: string;
readonly stack: readonly StackItemJSON[] | string;
readonly notifications: readonly NotificationJSON[];
}
Expand Down
38 changes: 11 additions & 27 deletions packages/neo-one-client-core/src/__tests__/provider/temp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,6 @@ describe('JSONRPCClient Tests', () => {
expect(memorypoolmaxtransactions).toBeDefined();
});

// TODO: run test
// test('getAllStorage', async () => {
// const storages = await client.getAllStorage(Hash160.NEO);

// expect(storages.length).toEqual(10);
// expect(storages[0]).toEqual({
// isConstant: false,
// key: 'feffffff0b',
// value: '7ee57ed872ab0a',
// });
// });

test('getNep5Balances', async () => {
const balances = await client.getNep5Balances(address);

Expand All @@ -212,7 +200,6 @@ describe('JSONRPCClient Tests', () => {
]);
});

// TODO: why are transfers and received equivalent?
test('getNep5Transfers', async () => {
const transfers = await client.getNep5Transfers(addressWithTransfers, 1468595301000, 1603753592250);

Expand Down Expand Up @@ -240,13 +227,12 @@ describe('JSONRPCClient Tests', () => {
});
});

// test('relayTransaction', async () => {
// const receipt = await client.relayTransaction();

// // TODO: test
// expect(receipt.transaction).toBeDefined();
// expect(receipt.verifyResult).toBeDefined();
// });
// TODO: run test/ debug
test('relayTransaction', async () => {
const receipt = await client.relayTransaction(Buffer.from([]).toString());
expect(receipt.transaction).toBeDefined();
expect(receipt.verifyResult).toBeDefined();
});

// TODO: run test/ debug
test('sendRawTransaction', async () => {
Expand All @@ -260,16 +246,14 @@ describe('JSONRPCClient Tests', () => {
expect(receipt).toEqual(true);
});

// TODO: run test
test('testInvokeRaw', async () => {
const { script, state, stack, gasconsumed, notifications } = await client.testInvokeRaw(
new ScriptBuilder().emitOp('PUSH0').build().toString('hex'),
);
const input = new ScriptBuilder().emitOp('PUSH0').build().toString('hex');
const { script, state, stack, gasconsumed, notifications } = await client.testInvokeRaw(input);

expect(script).toEqual('');
expect(script).toEqual('10');
expect(state).toEqual('HALT');
expect(stack).toEqual([]);
expect(gasconsumed).toEqual('0');
expect(stack).toEqual([{ type: 'Integer', value: '0' }]);
expect(gasconsumed).toEqual('30');
expect(notifications).toEqual([]);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/neo-one-node-rpc-handler/src/createHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ export const createHandler = ({
script: script.toString('hex'),
state: toVMStateJSON(result.state),
stack,
gasconsumed: result.gasConsumed,
gasconsumed: common.fixed8FromDecimal(result.gasConsumed.toString()).toString(),
notifications: result.notifications.map((n) => n.serializeJSON()),
};
} catch {
return {
script: script.toString('hex'),
state: toVMStateJSON(result.state),
stack: 'error: recursive reference',
gasconsumed: result.gasConsumed,
gasconsumed: common.fixed8FromDecimal(result.gasConsumed.toString()).toString(),
notifications: result.notifications.map((n) => n.serializeJSON()),
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/neo-one-node-vm/lib/Dispatcher.Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private bool _loadScript(Script script, CallFlags flag)
private bool _setInstructionPointer(int initialPosition)
{
this.isEngineInitialized();
this.engine.LoadClonedContext(initialPosition);
this.engine.CurrentContext.InstructionPointer = initialPosition;

return true;
}
Expand Down