import { DebuggerClient } from "../debugger-client" import request from 'sync-request'; import { InitArguments } from "../types"; import { safeNativize } from "../helper"; jest.setTimeout(50000); describe('Truffle debugger', () => { let client: DebuggerClient; beforeAll(async () => { client = new DebuggerClient(); const resp = request('GET', "https://test.sentio.xyz/api/v1/solidity/fetch_and_compile?txHash=0x857c1331d430048a16b71515464c6d68e7cc17337de82afe0151652435862b4a", {json: true}) const body = JSON.parse(resp.body as string); const shimmedCompilations = []; for (var key in body.result) { var value = body.result[key]; // @ts-ignore shimmedCompilations.push(value); } const init_args: InitArguments = { providerURL: 'https://test.sentio.xyz/api/v1/solidity', txnHash: "0x857c1331d430048a16b71515464c6d68e7cc17337de82afe0151652435862b4a", shimmedCompilations: shimmedCompilations, chainId: "0x1", storageLookup: false, disableOptimizer: false, } await client.initialize(init_args); }), afterEach(async () => { await client.reset(); }), it('advance multiple steps', async () => { await client.advance(100000); expect(client.finished).toBe(true); }), it('breakpoint and evaluate variables', async () => { await client.addBreakpoint({ compilationId: "externalFor(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)Via(etherscan)Number(0)", sourcePath: "FiatTokenProxy.sol", line: 21 }); expect((await client.continueUntilBreakpoint()).lines.start.line).toBe(21); expect(await client.evaluateExpression("now + 2")).toBe(1670734885); expect(await client.evaluateExpression("now + 1")).toBe(1670734884); }), it('require stacktrace and varaibles', async () => { await client.stepNext(); await client.stepInto(); await client.stepInto(); await client.stepInto(); await client.stepInto(); await client.stepInto(); await client.stepInto(); await client.stepInto(); await client.stepInto(); await client.stepInto(); expect(await client.stepOver()).not.toBeNull; expect(await client.requireStacktrace()).not.toBeNull; expect(await client.requireVariables()).not.toBeNull; }), it('Trace', async () => { const trace = (await client.getCallTrace()); expect(trace).not.toBeNull; }), it('Evaluate illegal expression', async () => { await client.evaluateExpression("@1").catch((e) => { expect(e).not.toBeNull; }); }) it('Get code', async () => { let private_client = new DebuggerClient(); const resp = request('GET', "https://test.sentio.xyz/api/v1/solidity/fetch_and_compile?txHash=0x9da0c2284049126f53921841c38604c074f3f224e71172a66d6d283db3ae09f6", {json: true}) const body = JSON.parse(resp.body as string); const shimmedCompilations = []; for (var key in body.result) { var value = body.result[key]; // @ts-ignore shimmedCompilations.push(value); } const init_args: InitArguments = { providerURL: 'https://test.sentio.xyz/api/v1/solidity', txnHash: "0x9da0c2284049126f53921841c38604c074f3f224e71172a66d6d283db3ae09f6", shimmedCompilations: shimmedCompilations, chainId: "0x1", storageLookup: false, disableOptimizer: false, } await private_client.initialize(init_args); await private_client.stepInto(); await private_client.stepInto(); await private_client.stepInto(); await private_client.stepInto(); await private_client.stepInto(); expect(await private_client.requireVariables()).not.toBeNull; expect(await private_client.getCallTrace()).not.toBeNull; }), it('test safeNative', () => { const res = safeNativize({ "type": { "typeClass": "uint", "bits": 256 }, "kind": "value", "value": { // @ts-ignore "asBN": { "negative": 0, "words": [ 58647702, 219 ], "length": 2, "red": null }, "rawAsBN": { "negative": 0, "words": [ 58647702, 219 ], "length": 2, "red": null } } }) expect(res).toBe(14755488918); }) })