Skip to content

Commit

Permalink
Merge pull request #62 from skalenetwork/hotfix/update-transfer-funct…
Browse files Browse the repository at this point in the history
…ion-interface

Remove reduntant log in base contract
  • Loading branch information
dmytrotkk authored Aug 22, 2023
2 parents a07988d + 182c3d9 commit 1840b08
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.5"
"typescript": "^5.1.6"
},
"dependencies": {
"debug": "^4.3.4",
Expand Down
5 changes: 0 additions & 5 deletions src/contracts/BaseContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
*/

import { ethers, Provider } from "ethers";
import debug from 'debug';


const log = debug('ima:contracts:BaseContract');


export class BaseContract {
Expand All @@ -35,7 +31,6 @@ export class BaseContract {
name: string;

constructor(provider: Provider, address: string, abi: any, name: string) {
log('Initing contract ' + this.constructor.name + ' at ' + address);
this.provider = provider;
this.address = address;
this.contract = new ethers.Contract(address, abi, provider);
Expand Down
19 changes: 0 additions & 19 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @copyright SKALE Labs 2021-Present
*/

import fs from 'fs';

import * as constants from './constants';
import InvalidCredentialsException from './exceptions/InvalidCredentialsException';
Expand All @@ -39,24 +38,6 @@ export function remove0x(s: any) {
return s.slice(2);
}

export function jsonFileLoad(path: string) {
if (!fileExists(path)) {
return {}
}
const s = fs.readFileSync(path);
const jo = JSON.parse(s.toString());
return jo;
}

export function fileExists(strPath: string) {
if (fs.existsSync(strPath)) {
const stats = fs.statSync(strPath);
if (stats.isFile())
return true;
}
return false;
}

export function validatePrivateKey(privateKey: string) {
if (!constants.PRIVATE_KEY_REGEX.test(privateKey)) {
throw new InvalidCredentialsException(constants.errorMessages.INVALID_PRIVATEKEY);
Expand Down
6 changes: 4 additions & 2 deletions src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ export async function send(
if (opts.value) transaction.value = opts.value;
if (opts.address) transaction.from = opts.address;

const gasLimit = await provider.estimateGas(transaction);
log('💡 ' + name + ' estimated gasLimit: ' + gasLimit);
const gasLimit = opts.customGasLimit ?? await provider.estimateGas(transaction);
transaction.gasLimit = gasLimit;
log('💡 ' + name + ' gasLimit: ' + gasLimit);

const signer = await getSigner(provider, opts);

Expand All @@ -56,6 +57,7 @@ export async function send(
log('⏳ ' + name + ' mining - tx: ' + txResponse.hash + ', nonce: ' +
txResponse.nonce + ', gasLimit: ' + txResponse.gasLimit);
if (wait) await provider.waitForTransaction(txResponse.hash);
// todo: handle failed tx!
log('✅ ' + name + ' mined - tx: ' + txResponse.hash);
return txResponse;
}
Expand Down
Empty file added test/helper.ts
Empty file.
30 changes: 25 additions & 5 deletions test/test_utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// import Web3 from 'web3';
// import {AbiItem} from 'web3-utils';
import fs from 'fs';

import { Wallet, Contract, Provider, JsonRpcProvider } from "ethers";

Expand Down Expand Up @@ -42,25 +43,44 @@ const NETWORKS = ['mainnet', 'schain'];
const TOKEN_NAME = 'TEST';



export function jsonFileLoad(path: string) {
if (!fileExists(path)) {
return {}
}
const s = fs.readFileSync(path);
const jo = JSON.parse(s.toString());
return jo;
}

export function fileExists(strPath: string) {
if (fs.existsSync(strPath)) {
const stats = fs.statSync(strPath);
if (stats.isFile())
return true;
}
return false;
}

export function initTestIMA() {
const providerMainnet = new JsonRpcProvider(MAINNET_ENDPOINT);
const providerSchain = new JsonRpcProvider(SCHAIN_ENDPOINT);
const mainnetAbi = helper.jsonFileLoad(MAINNET_ABI_FILEPATH);
const sChainAbi = helper.jsonFileLoad(SCHAIN_ABI_FILEPATH);
const mainnetAbi = jsonFileLoad(MAINNET_ABI_FILEPATH);
const sChainAbi = jsonFileLoad(SCHAIN_ABI_FILEPATH);
return new IMA(providerMainnet, providerSchain, mainnetAbi, sChainAbi)
}


export function initTestSChain() {
const provider = new JsonRpcProvider(SCHAIN_ENDPOINT);
const abi = helper.jsonFileLoad(SCHAIN_ABI_FILEPATH);
const abi = jsonFileLoad(SCHAIN_ABI_FILEPATH);
return new SChain(provider, abi);
}


export function initTestMainnet() {
const provider = new JsonRpcProvider(MAINNET_ENDPOINT);
const abi = helper.jsonFileLoad(MAINNET_ABI_FILEPATH);
const abi = jsonFileLoad(MAINNET_ABI_FILEPATH);
return new MainnetChain(provider, abi);
}

Expand Down Expand Up @@ -118,7 +138,7 @@ export function initTestTokens(
for (let i in NETWORKS) {
let network = NETWORKS[i];
let filepath = TOKENS_ABI_FOLDER + tokenName + 'Example-' + TOKEN_NAME + '-' + network + '.json';
let tokenMeta = helper.jsonFileLoad(filepath);
let tokenMeta = jsonFileLoad(filepath);
let keyName = network + tokenName;

let abiKey = tokenName.toLowerCase() + '_abi';
Expand Down
8 changes: 3 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
Expand Down Expand Up @@ -42,8 +42,8 @@
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "src", /* Base directory to resolve non-absolute module names. */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "src", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
Expand All @@ -66,8 +66,6 @@
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */

"resolveJsonModule": true
},
"exclude": [
"build",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3486,10 +3486,10 @@ type-fest@^0.21.3:
resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz"
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==

typescript@^4.1.5:
version "4.6.4"
resolved "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz"
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==
typescript@^5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==

unbox-primitive@^1.0.1:
version "1.0.2"
Expand Down

0 comments on commit 1840b08

Please sign in to comment.