Test for calling ethereum host API and updated eden subgraph (#29)

* Implement graph-ts eth-call API

* Tests for eden subgraph
This commit is contained in:
2021-12-28 16:08:05 +05:30
committed by nabarun
parent f34d83c04b
commit ca01fa788d
9 changed files with 64 additions and 61 deletions
+7 -4
View File
@@ -6,19 +6,22 @@ import path from 'path';
import { instantiate } from './index';
xdescribe('eden wasm loader tests', () => {
describe('eden wasm loader tests', () => {
it('should load the subgraph network wasm', async () => {
const filePath = path.resolve(__dirname, '../test/subgraph/eden/EdenNetwork/EdenNetwork.wasm');
await instantiate(filePath);
const { exports: { _start } } = await instantiate(filePath);
_start();
});
it('should load the subgraph network distribution wasm', async () => {
const filePath = path.resolve(__dirname, '../test/subgraph/eden/EdenNetworkDistribution/EdenNetworkDistribution.wasm');
await instantiate(filePath);
const { exports: { _start } } = await instantiate(filePath);
_start();
});
it('should load the subgraph network governance wasm', async () => {
const filePath = path.resolve(__dirname, '../test/subgraph/eden/EdenNetworkGovernance/EdenNetworkGovernance.wasm');
await instantiate(filePath);
const { exports: { _start } } = await instantiate(filePath);
_start();
});
});
+18 -19
View File
@@ -6,21 +6,21 @@ import fs from 'fs/promises';
import loader from 'assemblyscript/lib/loader';
import {
utils,
BigNumber
// getDefaultProvider,
// Contract
BigNumber,
getDefaultProvider,
Contract
} from 'ethers';
import { TypeId } from './types';
// import exampleAbi from '../test/subgraph/example1/build/Example1/abis/Example1.json';
import exampleAbi from '../test/subgraph/example1/build/Example1/abis/Example1.json';
// const NETWORK_URL = 'http://127.0.0.1:8545';
const NETWORK_URL = 'http://127.0.0.1:8081';
type idOfType = (TypeId: number) => number
export const instantiate = async (filePath: string): Promise<loader.ResultObject & { exports: any }> => {
const buffer = await fs.readFile(filePath);
// const provider = getDefaultProvider(NETWORK_URL);
const provider = getDefaultProvider(NETWORK_URL);
const imports: WebAssembly.Imports = {
index: {
@@ -112,29 +112,23 @@ export const instantiate = async (filePath: string): Promise<loader.ResultObject
const functionSignature = __getString(await smartContractCall.functionSignature);
const functionParams = __getArray(await smartContractCall.functionParams);
console.log(
'ethereum.call params',
__getString(await contractAddress.toHexString()),
contractName,
functionName,
functionSignature,
functionParams
);
console.log('ethereum.call params');
console.log('contractName:', contractName);
console.log('functionSignature:', functionSignature);
// TODO: Get ABI according to contractName.
// const contract = new Contract(__getString(contractAddress.toHexString()), exampleAbi, provider);
const contract = new Contract(__getString(await contractAddress.toHexString()), exampleAbi, provider);
try {
// TODO: Implement async function to perform eth_call.
// let result = await contract[functionName](...functionParams);
let result: any = 'test';
// TODO: Check for function overloading.
let result = await contract[functionName](...functionParams);
if (!Array.isArray(result)) {
result = [result];
}
const resultPtrArrayPromise = result.map(async (value: any) => {
// TODO: Create Value instance according to type.
// TODO: Create Value instance according to return type.
const ethValue = await ethereum.Value.fromString(await __newString(value));
return ethValue;
@@ -282,6 +276,11 @@ export const instantiate = async (filePath: string): Promise<loader.ResultObject
'bigInt.pow': () => {
console.log('bigInt.pow');
}
},
datasource: {
'dataSource.address': () => {
console.log('dataSource.address');
}
}
};