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

[Cleanup] Adjust versions / fix errors and linters #40

Merged
merged 1 commit into from
Feb 22, 2023
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
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ module.exports = {
sourceType: "module"
},
parser: '@typescript-eslint/parser',
rules: {
"@typescript-eslint/no-explicit-any": "off"
},
};
12 changes: 9 additions & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ jobs:
cd $GOPATH/$CAMPATH
git clone https://github.com/chain4travel/camino-network-runner --depth 1 -bv0.2.1-alpha1
- name: Starting Camino Network Runner
env:
CAMINO_NODE_PATH: ${{env.GOPATH}}/${{env.CAMPATH}}/camino-node/build/camino-node
shell: bash
run: |
cd $GOPATH/$CAMPATH
cd camino-network-runner
CAMINO_NODE_PATH=$GOPATH/$CAMPATH/camino-node/build/camino-node go run ./examples/local/fivenodenetwork/main.go &
go run ./examples/local/fivenodenetwork/main.go &>/tmp/cnr.log &
- name: CaminoJS E2E Test
env:
CAMINOGO_IP: localhost
CAMINOGO_IP: 127.0.0.1
CAMINOGO_PORT: 9650
run: sleep 60 && yarn test -i --roots e2e_tests
run: |
sleep 90
cat /tmp/cnr.log
yarn test -i --roots e2e_tests
14 changes: 12 additions & 2 deletions e2e_tests/cchain_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ import { EVMAPI } from "src/apis/evm"

describe("CChain", (): void => {
const avalanche: Avalanche = getAvalanche()
const cchain: EVMAPI = avalanche.CChain()
const keystore: KeystoreAPI = avalanche.NodeKeys()
var cchain: EVMAPI
var keystore: KeystoreAPI

beforeAll(() => {
return new Promise((resolve) => {
avalanche.fetchNetworkSettings().then((value) => {
cchain = avalanche.CChain()
keystore = new KeystoreAPI(avalanche)
resolve(value)
})
})
})

let exportTxHash = { value: "" }

Expand Down
11 changes: 10 additions & 1 deletion e2e_tests/health_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import Avalanche from "src"

describe("Info", (): void => {
const avalanche: Avalanche = getAvalanche()
const health: HealthAPI = avalanche.Health()
var health: HealthAPI

beforeAll(() => {
return new Promise((resolve) => {
avalanche.fetchNetworkSettings().then((value) => {
health = avalanche.Health()
resolve(value)
})
})
})

// test_name response_promise resp_fn matcher expected_value/obtained_value
const tests_spec: any = [
Expand Down
11 changes: 10 additions & 1 deletion e2e_tests/info_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ import Avalanche from "src"

describe("Info", (): void => {
const avalanche: Avalanche = getAvalanche()
const info: InfoAPI = avalanche.Info()
var info: InfoAPI

beforeAll(() => {
return new Promise((resolve) => {
avalanche.fetchNetworkSettings().then((value) => {
info = avalanche.Info()
resolve(value)
})
})
})

// test_name response_promise resp_fn matcher expected_value/obtained_value
const tests_spec: any = [
Expand Down
11 changes: 10 additions & 1 deletion e2e_tests/keystore_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ describe("Keystore", (): void => {
let exportedUser = { value: "" }

const avalanche: Avalanche = getAvalanche()
const keystore: KeystoreAPI = avalanche.NodeKeys()
var keystore: KeystoreAPI

beforeAll(() => {
return new Promise((resolve) => {
avalanche.fetchNetworkSettings().then((value) => {
keystore = new KeystoreAPI(avalanche)
resolve(value)
})
})
})

// test_name response_promise resp_fn matcher expected_value/obtained_value
const tests_spec: any = [
Expand Down
18 changes: 13 additions & 5 deletions e2e_tests/pchain_nomock.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAvalanche, createTests, Matcher } from "./e2etestlib"
import { KeystoreAPI } from "src/apis/keystore/api"
import BN from "bn.js"
import { PlatformVMAPI } from "src/apis/platformvm"

describe("PChain", (): void => {
let tx = { value: "" }
Expand All @@ -9,8 +10,18 @@ describe("PChain", (): void => {
let createdSubnetID = { value: "" }

const avalanche = getAvalanche()
const pchain = avalanche.PChain()
const keystore = new KeystoreAPI(avalanche)
var pchain: PlatformVMAPI
var keystore: KeystoreAPI

beforeAll(() => {
return new Promise((resolve) => {
avalanche.fetchNetworkSettings().then((value) => {
pchain = avalanche.PChain()
keystore = new KeystoreAPI(avalanche)
resolve(value)
})
})
})

const now: number = new Date().getTime()
const startTime: Date = new Date(now + 800)
Expand All @@ -21,13 +32,10 @@ describe("PChain", (): void => {
const passwd: string = "avalancheJsP@ssw4rd"
const badUser: string = "asdfasdfsa"
const badPass: string = "pass"
const memo: string = "hello world"
const whaleAddr: string = "P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p"
const key: string =
"PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
const nodeID: string = "NodeID-AK7sPBsZM9rQwse23aLhEEBPHZD5gkLrL"
const subnetID: string = "2bGsYJorY6X7RhjPBFs3kYjiNEHo4zGrD2eeyZbb43T2KKi7fM"
const xChainAddr: string = "X-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p"
const avalancheBlockChainID: string = "11111111111111111111111111111111LpoYY"

const rewardUTXOTxID: string =
Expand Down
15 changes: 13 additions & 2 deletions e2e_tests/xchain_nomock.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAvalanche, createTests, Matcher } from "./e2etestlib"
import { KeystoreAPI } from "src/apis/keystore/api"
import BN from "bn.js"
import { AVMAPI } from "src/apis/avm"

describe("XChain", (): void => {
let tx = { value: "" }
Expand All @@ -9,8 +10,18 @@ describe("XChain", (): void => {
let addrC = { value: "" }

const avalanche = getAvalanche()
const xchain = avalanche.XChain()
const keystore = new KeystoreAPI(avalanche)
var xchain: AVMAPI
var keystore: KeystoreAPI

beforeAll(() => {
return new Promise((resolve) => {
avalanche.fetchNetworkSettings().then((value) => {
xchain = avalanche.XChain()
keystore = new KeystoreAPI(avalanche)
resolve(value)
})
})
})

const user: string = "avalancheJsXChainUser"
const passwd: string = "avalancheJsP1ssw4rd"
Expand Down
9 changes: 9 additions & 0 deletions examples/bintools/privkey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BinTools, Buffer } from "@c4tplatform/caminojs/dist"
const bintools: BinTools = BinTools.getInstance()

const ethPrivateKey =
"56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027"
const ethPrivateKeyBuf = Buffer.from(ethPrivateKey, "hex")

let cPrivKey = `PrivateKey-` + bintools.cb58Encode(ethPrivateKeyBuf)
console.log(cPrivKey)
9 changes: 1 addition & 8 deletions examples/evm/buildImportTx-PChain.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Avalanche, BN } from "@c4tplatform/caminojs/dist"
import {
PlatformVMAPI,
KeyChain as PlatformVMKeyChain
} from "@c4tplatform/caminojs/dist/apis/platformvm"
import { PlatformVMAPI } from "@c4tplatform/caminojs/dist/apis/platformvm"
import {
EVMAPI,
KeyChain as EVMKeyChain,
Expand Down Expand Up @@ -32,7 +29,6 @@ let pchain: PlatformVMAPI
let cchain: EVMAPI
let pKeychain: PlatformKeyChain
let cKeychain: EVMKeyChain
let pAddressStrings: string[]
let cAddressStrings: string[]
let pChainBlockchainId: string

Expand All @@ -44,7 +40,6 @@ const InitAvalanche = async () => {
cKeychain = cchain.keyChain()
pKeychain.importKey(privKey)
cKeychain.importKey(privKey)
pAddressStrings = pchain.keyChain().getAddressStrings()
cAddressStrings = cchain.keyChain().getAddressStrings()
pChainBlockchainId = avalanche.getNetwork().P.blockchainID
}
Expand All @@ -65,7 +60,6 @@ const main = async (): Promise<any> => {
cHexAddress,
cAddressStrings,
pChainBlockchainId,
cAddressStrings,
fee
)
const importCost: number = costImportTx(avalanche.getNetwork().C, unsignedTx)
Expand All @@ -76,7 +70,6 @@ const main = async (): Promise<any> => {
cHexAddress,
cAddressStrings,
pChainBlockchainId,
cAddressStrings,
fee
)

Expand Down
2 changes: 0 additions & 2 deletions examples/evm/buildImportTx-xchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const main = async (): Promise<any> => {
cHexAddress,
cAddressStrings,
xChainBlockchainId,
cAddressStrings,
fee
)
const importCost: number = costImportTx(avalanche.getNetwork().C, unsignedTx)
Expand All @@ -73,7 +72,6 @@ const main = async (): Promise<any> => {
cHexAddress,
cAddressStrings,
xChainBlockchainId,
cAddressStrings,
fee
)

Expand Down
2 changes: 1 addition & 1 deletion examples/mnemonic/validateMnemonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const main = async (): Promise<any> => {
const m: string =
"output tooth keep tooth bracket fox city sustain blood raise install pond stem reject long scene clap gloom purpose mean music piece unknown light"
const wordlist = mnemonic.getWordlists("english") as string[]
const validateMnemonic: string = mnemonic.validateMnemonic(m, wordlist)
const validateMnemonic = mnemonic.validateMnemonic(m, wordlist)
console.log(validateMnemonic)
}
main()
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@
"@types/create-hash": "1.2.2",
"@types/hdkey": "2.0.1",
"@types/jest": "27.5.0",
"@types/node": "16.11.12",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"clean-webpack-plugin": "4.0.0",
"eslint": "7.32.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-security": "1.5.0",
Expand All @@ -65,30 +64,30 @@
"jest": "26.6.3",
"jest-mock-axios": "4.5.0",
"prettier": "2.7.1",
"terser-webpack-plugin": "5.3.5",
"terser-webpack-plugin": "^5.3.1",
"ts-jest": "26.5.6",
"ts-loader": "9.3.1",
"typedoc": "^0.18.0",
"typedoc-plugin-external-module-name": "^4.0.3",
"typedoc-plugin-markdown": "^2.4.0",
"typescript": "4.7.4",
"webpack": "5.74.0",
"webpack-cli": "4.10.0"
"webpack": "^5.54.0",
"webpack-cli": "^4.8.0"
},
"engines": {
"node": ">=14.0.0"
},
"dependencies": {
"assert": "2.0.0",
"axios": "0.27.2",
"axios": "^0.26.1",
"bech32": "2.0.0",
"bip39": "3.0.4",
"bn.js": "5.2.1",
"buffer": "6.0.3",
"bip39": "^3.0.4",
"bn.js": "5.1.1",
"buffer": "5.4.3",
"create-hash": "1.2.0",
"crypto-browserify": "3.12.0",
"elliptic": "6.5.4",
"ethers": "5.7.0",
"ethers": "^5.7.2",
"hdkey": "2.0.1",
"isomorphic-ws": "5.0.0",
"randombytes": "^2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/apis/avm/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ export class AVMAPI extends JRPCAPI {
) {
/* istanbul ignore next */
throw new AddressError(
"Error - AVMAPI.${caller}: Invalid address format"
`Error - AVMAPI.${caller}: Invalid address format`
)
}
addrs.push(addresses[`${i}`] as string)
Expand Down
4 changes: 2 additions & 2 deletions src/apis/avm/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface iUTXOID {
outputIndex: number
}

export interface CreateAddressParams extends CredsInterface {}
export type CreateAddressParams = CredsInterface

export interface CreateFixedCapAssetParams extends CredsInterface {
name: string
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface ImportParams extends CredsInterface {
sourceChain: string
}

export interface ListAddressesParams extends CredsInterface {}
export type ListAddressesParams = CredsInterface

export interface GetAllBalancesParams {
address: string
Expand Down
2 changes: 0 additions & 2 deletions src/apis/avm/keychain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import { Buffer } from "buffer/"
import BinTools from "../../utils/bintools"
import { SECP256k1KeyChain, SECP256k1KeyPair } from "../../common/secp256k1"
import { Serialization, SerializedType } from "../../utils"

/**
* @ignore
*/
const bintools: BinTools = BinTools.getInstance()
const serialization: Serialization = Serialization.getInstance()

/**
* Class for representing a private and public keypair on an AVM Chain.
Expand Down
2 changes: 1 addition & 1 deletion src/apis/avm/ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ export class UTXOID extends NBytes {
return newbase as this
}

create(...args: any[]): this {
create(): this {
return new UTXOID() as this
}

Expand Down
8 changes: 4 additions & 4 deletions src/apis/avm/utxos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class UTXOSet extends StandardUTXOSet<UTXO> {

deserialize(fields: object, encoding: SerializedEncoding = "hex") {
super.deserialize(fields, encoding)
let utxos = {}
let utxos: { [key: string]: UTXO } = {}
for (let utxoid in fields["utxos"]) {
let utxoidCleaned: string = serialization.decoder(
utxoid,
Expand All @@ -158,15 +158,15 @@ export class UTXOSet extends StandardUTXOSet<UTXO> {
encoding
)
}
let addressUTXOs = {}
let addressUTXOs: { [key: string]: { [key: string]: BN } } = {}
for (let address in fields["addressUTXOs"]) {
let addressCleaned: string = serialization.decoder(
address,
encoding,
"cb58",
"hex"
)
let utxobalance: {} = {}
let utxobalance: { [key: string]: BN } = {}
for (let utxoid in fields["addressUTXOs"][`${address}`]) {
let utxoidCleaned: string = serialization.decoder(
utxoid,
Expand Down Expand Up @@ -203,7 +203,7 @@ export class UTXOSet extends StandardUTXOSet<UTXO> {
return utxovar
}

create(...args: any[]): this {
create(): this {
return new UTXOSet() as this
}

Expand Down
Loading