Skip to content

Commit

Permalink
Merge pull request #115 from Juneo-io/dev
Browse files Browse the repository at this point in the history
v0.0.96
  • Loading branch information
alekswaslet authored May 29, 2024
2 parents cb90bcd + 74a58e8 commit 0bdfd23
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 180 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "juneojs",
"version": "0.0.95",
"version": "0.0.96",
"description": "Juneo JS Library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
13 changes: 9 additions & 4 deletions src/wallet/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HDNodeWallet, Mnemonic, Wallet, randomBytes } from 'ethers'
import { JEVM_ID, type Blockchain, JVM_ID, PLATFORMVM_ID, type JEVMBlockchain } from '../chain'
import { HDNodeWallet, Mnemonic, randomBytes, Wallet } from 'ethers'
import { JEVM_ID, JVM_ID, PLATFORMVM_ID, type Blockchain, type JEVMBlockchain } from '../chain'
import { MainNetwork } from '../network'
import {
ECKeyPair,
encodeJuneoAddress,
Expand All @@ -9,7 +10,6 @@ import {
WalletError
} from '../utils'
import * as encoding from '../utils/encoding'
import { TestNetwork } from '../network'

const EVMHdPath = "m/44'/60'/0'/0"
const JVMHdPath = "m/44'/9000'/0'/0"
Expand Down Expand Up @@ -41,7 +41,7 @@ export class MCNWallet {
privateKey?: string
chainsWallets = new Map<string, VMWallet>()

private constructor (hrp: string = TestNetwork.hrp) {
private constructor (hrp: string = MainNetwork.hrp) {
this.hrp = hrp
}

Expand Down Expand Up @@ -71,6 +71,11 @@ export class MCNWallet {
return wallets
}

setHrp (hrp: string): void {
this.hrp = hrp
this.chainsWallets.clear()
}

private setChainWallet (chain: Blockchain): void {
if (chain.vmId === JEVM_ID) {
this.chainsWallets.set(chain.id, this.buildJEVMWallet(chain))
Expand Down
41 changes: 20 additions & 21 deletions tests/e2e/api/info.test.ts
Original file line number Diff line number Diff line change
@@ -1,101 +1,100 @@
import { MCNProvider, GenesisJUNEChain, GenesisNetwork } from '../../../src'
import { GenesisJUNEChain } from '../../../src'
import { PROVIDER } from '../constants'

describe('InfoAPI', () => {
const provider: MCNProvider = new MCNProvider(GenesisNetwork)

describe('isBootstrapped', () => {
test.each([{ chainID: GenesisJUNEChain.id }])('Valid: $chainID', async ({ chainID }) => {
const result = await provider.info.isBootstrapped(chainID)
const result = await PROVIDER.info.isBootstrapped(chainID)
expect(result.isBootstrapped).toEqual(true)
})
test.failing.each([{ chainID: 'WRONG_CHAIN_ID' }])('Invalid: $chainID', async ({ chainID }) => {
await provider.info.isBootstrapped('WRONG_CHAIN_ID')
await PROVIDER.info.isBootstrapped('WRONG_CHAIN_ID')
})
})

describe('getBlockchainID', () => {
test.each([{ alias: 'JUNE' }])('Valid: $alias', async ({ alias }) => {
const result = await provider.info.getBlockchainID(alias)
const result = await PROVIDER.info.getBlockchainID(alias)
expect(result.blockchainID).toEqual(GenesisJUNEChain.id)
})
test.failing.each([{ alias: 'WRONG_ALIAS' }])('Invalid: $alias', async ({ alias }) => {
await provider.info.getBlockchainID('alias')
await PROVIDER.info.getBlockchainID('alias')
})
})

describe('getNetworkID', () => {
test('Returns correct network id', async () => {
const result = await provider.info.getNetworkID()
expect(result.networkID).toEqual(provider.mcn.id.toString())
const result = await PROVIDER.info.getNetworkID()
expect(result.networkID).toEqual(PROVIDER.mcn.id.toString())
})
})

describe('getNetworkName', () => {
test('Returns correct network name', async () => {
const result = await provider.info.getNetworkName()
expect(result.networkName).toEqual(provider.mcn.hrp)
const result = await PROVIDER.info.getNetworkName()
expect(result.networkName).toEqual(PROVIDER.mcn.hrp)
})
})

describe('getNodeID', () => {
test('Returns node id', async () => {
const result = await provider.info.getNodeID()
const result = await PROVIDER.info.getNodeID()
expect(result).toBeDefined()
})
})

describe('getNodeIP', () => {
test('Returns node ip', async () => {
const result = await provider.info.getNodeIP()
const result = await PROVIDER.info.getNodeIP()
expect(result).toBeDefined()
})
})

describe('getNodeVersion', () => {
test('Returns node version', async () => {
const result = await provider.info.getNodeVersion()
const result = await PROVIDER.info.getNodeVersion()
expect(result).toBeDefined()
})
})

describe('getTxFee', () => {
test('Returns fee config', async () => {
const result = await provider.info.getTxFee()
const result = await PROVIDER.info.getTxFee()
expect(result).toBeDefined()
})
test('Returns cached fee config', async () => {
const result = await provider.info.getTxFee()
const result = await PROVIDER.info.getTxFee()
expect(result).toBeDefined()
})
test('Returns updated fee config', async () => {
const result = await provider.info.getTxFee(true)
const result = await PROVIDER.info.getTxFee(true)
expect(result).toBeDefined()
})
})

describe('getVMs', () => {
test('Returns installed VMs', async () => {
const result = await provider.info.getVMs()
const result = await PROVIDER.info.getVMs()
expect(result).toBeDefined()
})
})

describe('peers', () => {
test('Returns list of peers', async () => {
const result = await provider.info.peers()
const result = await PROVIDER.info.peers()
expect(result).toBeDefined()
})
test.failing.each([
{ nodeIDs: ['WRONG_NODE_ID', 'NodeID-P1ESFUf8tutmR8hszZUWsXAJEKARZ5SPw'] },
{ nodeIDs: ['NodeID-P1ESFUf8tutmR8hszZUWsXAJEKARZ5SPa'] }
])('Invalid: $nodeIDs', async ({ nodeIDs }) => {
await provider.info.peers(nodeIDs)
await PROVIDER.info.peers(nodeIDs)
})
})

describe('uptime', () => {
test.failing.each([{ supernetID: 'WRONG_SUPERNET_ID' }])('Invalid: $supernetID', async ({ supernetID }) => {
await provider.info.uptime(supernetID)
await PROVIDER.info.uptime(supernetID)
})
})
})
15 changes: 7 additions & 8 deletions tests/e2e/api/jevm.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { MCNProvider, GenesisEUROC1Asset, GenesisJUNEChain, GenesisNetwork } from '../../../src'
import { GenesisEUROC1Asset, GenesisJUNEChain } from '../../../src'
import { PROVIDER } from '../constants'

describe('JEVMAPI', () => {
const provider: MCNProvider = new MCNProvider(GenesisNetwork)

describe('getTx', () => {
test.failing.each([
{ txID: '241mEKvJjtzAbVxvSsooEaAYgXkaipSDuxEoXBxBDP8mKHb8Cm' },
{ txID: '0x3c529e9941b6ca0ec34948c7f797e94ff810643ef64896c409ea0df36be9e554' },
{ txID: 'INVALID_TX_ID' }
])('Invalid: $txID', async ({ txID }) => {
const result = await provider.jevmApi[GenesisJUNEChain.id].getTx(txID)
const result = await PROVIDER.jevmApi[GenesisJUNEChain.id].getTx(txID)
expect(result.tx).toBeDefined()
})
})
Expand All @@ -35,27 +34,27 @@ describe('JEVMAPI', () => {
assetID: '0x0'
}
])('$description: $address, $block, $assetID', async ({ address, block, assetID }) => {
await provider.jevmApi[GenesisJUNEChain.id].eth_getAssetBalance(address, block, assetID)
await PROVIDER.jevmApi[GenesisJUNEChain.id].eth_getAssetBalance(address, block, assetID)
})
})

describe('eth_baseFee', () => {
test('Returns base fee', async () => {
const result = await provider.jevmApi[GenesisJUNEChain.id].eth_baseFee()
const result = await PROVIDER.jevmApi[GenesisJUNEChain.id].eth_baseFee()
expect(result).toBeDefined()
})
})

describe('eth_maxPriorityFeePerGas', () => {
test('Returns max priority fee per gas', async () => {
const result = await provider.jevmApi[GenesisJUNEChain.id].eth_maxPriorityFeePerGas()
const result = await PROVIDER.jevmApi[GenesisJUNEChain.id].eth_maxPriorityFeePerGas()
expect(result).toBeDefined()
})
})

describe('eth_getChainConfig', () => {
test('Returns chain config', async () => {
const result = await provider.jevmApi[GenesisJUNEChain.id].eth_getChainConfig()
const result = await PROVIDER.jevmApi[GenesisJUNEChain.id].eth_getChainConfig()
expect(result).toBeDefined()
})
})
Expand Down
27 changes: 12 additions & 15 deletions tests/e2e/api/jvm.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import {
MCNProvider,
GenesisBCH1Asset,
GenesisETH1Asset,
GenesisJUNEAsset,
type GetAssetDescriptionResponse,
type GetBlockResponse,
type GetHeightResponse,
type GetTxResponse,
GenesisNetwork,
GenesisJUNEAsset,
GenesisETH1Asset,
GenesisBCH1Asset
type GetTxResponse
} from '../../../src'
import { PROVIDER } from '../constants'

describe('JVMAPI', () => {
const provider: MCNProvider = new MCNProvider(GenesisNetwork)

describe('buildGenesis', () => {
// TODO later
})
Expand All @@ -21,7 +18,7 @@ describe('JVMAPI', () => {
test.each([{ asset: GenesisJUNEAsset }, { asset: GenesisETH1Asset }, { asset: GenesisBCH1Asset }])(
'Valid: $asset.assetId ($asset.symbol)',
async ({ asset }) => {
const result: GetAssetDescriptionResponse = await provider.jvmApi.getAssetDescription(asset.assetId)
const result: GetAssetDescriptionResponse = await PROVIDER.jvmApi.getAssetDescription(asset.assetId)
// TODO in Socotra2 use asset name
expect(result.name).toBeDefined()
expect(result.symbol).toEqual(asset.symbol)
Expand All @@ -34,7 +31,7 @@ describe('JVMAPI', () => {
{ assetId: '2RcLCZTsxSnvzeBvtrjRo8PCzLXuecHBoyr8DNp1R8ob8kHkbZ' },
{ assetId: 'INVALID_ASSET_ID' }
])('Invalid: $assetId', async ({ assetId }) => {
const result: GetAssetDescriptionResponse = await provider.jvmApi.getAssetDescription(assetId)
const result: GetAssetDescriptionResponse = await PROVIDER.jvmApi.getAssetDescription(assetId)
expect(result.name).toBeDefined()
})
})
Expand All @@ -47,7 +44,7 @@ describe('JVMAPI', () => {
test.each([{ height: 1 }, { height: 10 }, { height: 100 }, { height: null }, { height: undefined }])(
'Valid: $height',
async ({ height }) => {
const result: GetBlockResponse = await provider.jvmApi.getBlockByHeight(height as any)
const result: GetBlockResponse = await PROVIDER.jvmApi.getBlockByHeight(height as any)
expect(result.block).toBeDefined()
expect(result.encoding).toBeDefined()
}
Expand All @@ -59,13 +56,13 @@ describe('JVMAPI', () => {
{ description: 'Object input', height: {} },
{ description: 'Array input', height: [] }
])('$description: $height', async ({ height }) => {
await provider.jvmApi.getBlockByHeight(height as any)
await PROVIDER.jvmApi.getBlockByHeight(height as any)
})
})

describe('getHeight', () => {
test('Returns height', async () => {
const result: GetHeightResponse = await provider.jvmApi.getHeight()
const result: GetHeightResponse = await PROVIDER.jvmApi.getHeight()
expect(result.height).toBeDefined()
})
})
Expand All @@ -75,7 +72,7 @@ describe('JVMAPI', () => {
{ txID: 'dGJVWGj3GHQRAvt87xqcVUwKNKcJRaB7iUwGpNP9PYSrk6rie' },
{ txID: '2FKNX3WoJwtbanNxVV44qaXsv8SgkiBtD4psHC2wdbLizXvGS' }
])('Valid: $txID', async ({ txID }) => {
const result: GetTxResponse = await provider.jvmApi.getTx(txID)
const result: GetTxResponse = await PROVIDER.jvmApi.getTx(txID)
expect(result.encoding).toBeDefined()
expect(result.tx).toBeDefined()
})
Expand All @@ -88,7 +85,7 @@ describe('JVMAPI', () => {
{ description: 'Object input', txID: {} },
{ description: 'Array input', txID: [] }
])('$description: $txID', async ({ txID }) => {
await provider.jvmApi.getTx(txID as any)
await PROVIDER.jvmApi.getTx(txID as any)
})
})

Expand Down
Loading

0 comments on commit 0bdfd23

Please sign in to comment.