toI64 debugging changes

This commit is contained in:
Prathamesh Musale 2023-11-22 12:01:20 +05:30
parent d455a95c9f
commit e2aa023ead
6 changed files with 831 additions and 145 deletions

View File

@ -41,7 +41,7 @@
"asbuild:release": "asc assembly/index.ts --lib ./node_modules --exportRuntime --target release --runPasses asyncify", "asbuild:release": "asc assembly/index.ts --lib ./node_modules --exportRuntime --target release --runPasses asyncify",
"asbuild": "yarn asbuild:debug && yarn asbuild:release", "asbuild": "yarn asbuild:debug && yarn asbuild:release",
"test:init": "cp .env.example .env && yarn build:example", "test:init": "cp .env.example .env && yarn build:example",
"test": "yarn asbuild:debug && DEBUG=vulcanize:* node node_modules/.bin/_mocha src/**/*.test.ts", "test": "DEBUG=vulcanize:* node node_modules/.bin/_mocha src/**/json.test.ts",
"build:example": "cd test/subgraph/example1 && yarn && yarn codegen && yarn build", "build:example": "cd test/subgraph/example1 && yarn && yarn codegen && yarn build",
"watch": "DEBUG=vulcanize:* nodemon --watch src src/watcher.ts", "watch": "DEBUG=vulcanize:* nodemon --watch src src/watcher.ts",
"compare-entity": "node bin/compare-entity", "compare-entity": "node bin/compare-entity",

View File

@ -50,7 +50,7 @@ describe('json host api', () => {
await testJsonFromBytes(); await testJsonFromBytes();
}); });
it('should parse JSON safely', async () => { xit('should parse JSON safely', async () => {
const { testJsonTryFromBytes } = exports; const { testJsonTryFromBytes } = exports;
await testJsonTryFromBytes(); await testJsonTryFromBytes();

View File

@ -515,7 +515,10 @@ export const instantiate = async (
return isEqual; return isEqual;
}, },
'bigInt.fromString': async (s: number) => { 'bigInt.fromString': async (s: number) => {
console.log('before __getString');
const string = __getString(s); const string = __getString(s);
console.log('string', string);
console.log('after __getString');
// The BN is being stored as a byte array in wasm memory in 2's compliment representation and interpreted as such in other APIs. // The BN is being stored as a byte array in wasm memory in 2's compliment representation and interpreted as such in other APIs.
// Create a BN in 2's compliment representation. // Create a BN in 2's compliment representation.
@ -533,6 +536,7 @@ export const instantiate = async (
const bytes = bigNumber.toArray(BN_ENDIANNESS, bnSize); const bytes = bigNumber.toArray(BN_ENDIANNESS, bnSize);
const uint8ArrayId = await getIdOfType(TypeId.Uint8Array); const uint8ArrayId = await getIdOfType(TypeId.Uint8Array);
console.log('before __newArray');
const ptr = await __newArray(uint8ArrayId, bytes); const ptr = await __newArray(uint8ArrayId, bytes);
const bigInt = await ASBigInt.fromSignedBytes(ptr); const bigInt = await ASBigInt.fromSignedBytes(ptr);
@ -770,16 +774,37 @@ export const instantiate = async (
// TODO: Number methods do not work as 64bit values are not supported in js. // TODO: Number methods do not work as 64bit values are not supported in js.
// Tried solution in https://github.com/AssemblyScript/assemblyscript/issues/117#issuecomment-531556954 // Tried solution in https://github.com/AssemblyScript/assemblyscript/issues/117#issuecomment-531556954
'json.toI64': async (decimal: number) => { 'json.toI64': async (decimal: number) => {
return BigInt(__getString(decimal)); console.log('decimal toI64', __getString(decimal));
const ptr = await __newString(__getString(decimal));
try {
const y = await ASBigInt.fromString(ptr);
console.log('y', y);
} catch (error) {
console.log('error', error);
}
return BigInt(__getString(ptr));
}, },
'json.toU64': async (decimal: number) => { 'json.toU64': async (decimal: number) => {
console.log('decimal toU64', __getString(decimal));
return BigInt(__getString(decimal)); return BigInt(__getString(decimal));
}, },
'json.toF64': async (decimal: number) => { 'json.toF64': async (decimal: number) => {
console.log('decimal toF64', __getString(decimal));
return BigInt(__getString(decimal)); return BigInt(__getString(decimal));
}, },
'json.toBigInt': async (decimal: number) => { 'json.toBigInt': async (decimal: number) => {
console.log('decimal toBigInt', __getString(decimal));
const ptr = await __newString(__getString(decimal)); const ptr = await __newString(__getString(decimal));
try {
const y = await ASBigInt.fromString(ptr);
console.log('y', y);
} catch (error) {
console.log('error', error);
}
return ASBigInt.fromString(ptr); return ASBigInt.fromString(ptr);
} }
} }

View File

@ -10,7 +10,7 @@
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 example1" "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 example1"
}, },
"dependencies": { "dependencies": {
"@graphprotocol/graph-ts": "npm:@cerc-io/graph-ts@0.22.1-watcher-ts-0.1.0", "@graphprotocol/graph-ts": "npm:@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.3",
"@cerc-io/graph-cli": "0.22.4-watcher-ts-0.1.2" "@cerc-io/graph-cli": "0.32.0-watcher-ts-0.1.3"
} }
} }

View File

@ -565,6 +565,7 @@ export function testJsonFromBytes (): void {
); );
const jsonData = json.fromBytes(data); const jsonData = json.fromBytes(data);
log.debug('jsonData.kind {}', [jsonData.kind.toString()]);
assert(jsonData.kind === JSONValueKind.OBJECT, 'JSON value is not an object'); assert(jsonData.kind === JSONValueKind.OBJECT, 'JSON value is not an object');
const stringValue = jsonData.toObject().get('stringValue')!; const stringValue = jsonData.toObject().get('stringValue')!;
@ -577,13 +578,16 @@ export function testJsonFromBytes (): void {
const numberValue = jsonData.toObject().get('numberValue')!; const numberValue = jsonData.toObject().get('numberValue')!;
assert(numberValue.kind === JSONValueKind.NUMBER, 'JSON value is not a number'); assert(numberValue.kind === JSONValueKind.NUMBER, 'JSON value is not a number');
// TODO: Debug json toI64 failing test case. log.debug('numberValue.kind {}', [numberValue.kind.toString()]);
// const i64Value = numberValue.toI64();
// assert(i64Value == 123, 'values are not equal');
const bigIntValue = numberValue.toBigInt(); const bigIntValue = numberValue.toBigInt();
const expectedBigInt = BigInt.fromString('123'); const expectedBigInt = BigInt.fromString('123');
assert(bigIntValue.equals(expectedBigInt), 'BigInt values are not equal'); assert(bigIntValue.equals(expectedBigInt), 'BigInt values are not equal');
// TODO: Debug json toI64 failing test case.
log.debug('numberValue.kind {}', [numberValue.kind.toString()]);
const i64Value = numberValue.toI64();
log.debug('i64Value: {}', [i64Value.toString()]);
assert(i64Value === 123, 'values are not equal');
} }
export function testJsonTryFromBytes (): void { export function testJsonTryFromBytes (): void {

File diff suppressed because it is too large Load Diff