Skip to content
Open
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
100 changes: 50 additions & 50 deletions src/__tests__/BGL.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
import * as matchers from 'jest-extended'
import * as matchers from 'jest-extended';

import { IBridgeConfig } from '../types'
import { IBridgeConfig } from '../types';

import {
BGL,
BGLWBGLExchangePair,
ChainNames,
ChaindIds
} from '../'
import { BGL, BGLWBGLExchangePair, ChainNames, ChaindIds } from '../';

import {
ethers,
Wallet
} from 'ethers'
import { ethers, Wallet } from 'ethers';

expect.extend(matchers);
const TIME_OUT_MS = 10 * 1000;
const hasBridgeIntegrationEnv =
process.env.RUN_BRIDGE_INTEGRATION_TESTS === 'true' &&
Boolean(process.env.EVM_PRIVATE_KEY) &&
Boolean(process.env.BGL_PRIVATEKEY_OR_SEED);
const describeBridgeIntegration = hasBridgeIntegrationEnv
? describe
: describe.skip;

expect.extend(matchers)
const TIME_OUT_MS = 10 * 1000
jest.setTimeout(TIME_OUT_MS);

jest.setTimeout(TIME_OUT_MS)

describe('BGL class tests on BNB Chain', () => {

let BGLInstance: BGL
describeBridgeIntegration('BGL class tests on BNB Chain', () => {
let BGLInstance: BGL;
// let provider
let signer: ethers.Wallet
let recepientBNBAddress: string
let signer: ethers.Wallet;
let recepientBNBAddress: string;

beforeAll(async () => {
const bscProviderRpc = 'https://rpc.ankr.com/bsc'
const bscProviderRpc = 'https://rpc.ankr.com/bsc';
// const MNEMONIC = process.env.MNEMONIC as string
// const bglSeedPhrase = process.env.BGL_SEEDPHRASE
const bglPrivateKey = process.env.BGL_PRIVATEKEY_OR_SEED
const bglPrivateKey = process.env.BGL_PRIVATEKEY_OR_SEED;

const provider = new ethers.providers.JsonRpcProvider(bscProviderRpc)
const provider = new ethers.providers.JsonRpcProvider(bscProviderRpc);
// const provider = new ethers.providers.Web3Provider(window.etherum)

const config: IBridgeConfig = {
Expand All @@ -43,32 +40,35 @@ describe('BGL class tests on BNB Chain', () => {
chainId: ChaindIds.BNBSmartChain,
bridgeEndpoint: 'https://bglswap.com/app/',
// bglSeedPhrase: bglSeedPhrase
bglPrivateKeyOrSeed: bglPrivateKey as string
}
bglPrivateKeyOrSeed: bglPrivateKey as string,
};

BGLInstance = new BGL(config)
signer = new Wallet(config.evmPrivateKey, provider)
recepientBNBAddress = await signer.getAddress()
console.log('account:', recepientBNBAddress)
})
BGLInstance = new BGL(config);
signer = new Wallet(config.evmPrivateKey, provider);
recepientBNBAddress = await signer.getAddress();
});

it('test that BGL class instantiates correctly', () => {
expect(BGLInstance).toBeInstanceOf(BGL)
})

it('should swap BGL for WBGL Tokens', async () => {
const bglAmountToSwap = 1 // 1BGL
const bglTxFee = 0.0001 // minimum txFee of proposed 10,000 satoshis(0.0001BGL)

const bGLWBGLExchangePair: BGLWBGLExchangePair = {
recepientWBGLAddress: recepientBNBAddress,
bglAmount: bglAmountToSwap,
bglFee: bglTxFee
}

const swapResult = await BGLInstance.swapBGLforWBGL(bGLWBGLExchangePair)
// console.log(swapResult)
expect(swapResult.bglTxHash).toBeDefined()
expect(swapResult.rpcResult.error).toBe(null)
}, 15 * 1000)
})
expect(BGLInstance).toBeInstanceOf(BGL);
});

it(
'should swap BGL for WBGL Tokens',
async () => {
const bglAmountToSwap = 1; // 1BGL
const bglTxFee = 0.0001; // minimum txFee of proposed 10,000 satoshis(0.0001BGL)

const bGLWBGLExchangePair: BGLWBGLExchangePair = {
recepientWBGLAddress: recepientBNBAddress,
bglAmount: bglAmountToSwap,
bglFee: bglTxFee,
};

const swapResult = await BGLInstance.swapBGLforWBGL(bGLWBGLExchangePair);
// console.log(swapResult)
expect(swapResult.bglTxHash).toBeDefined();
expect(swapResult.rpcResult.error).toBe(null);
},
15 * 1000,
);
});
83 changes: 42 additions & 41 deletions src/__tests__/WBGL.test.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
import { ethers } from 'ethers'
import * as matchers from 'jest-extended'

import WBGLBridgeSDK, {
ChaindIds,
ChainNames,
IBridgeConfig,
WBGL
} from '../'
import { WBGLBGLExchangePair } from '../bridge/WBGL'

expect.extend(matchers)

console.log(process.env.evmPrivateKey)
describe('WBGL class tests on Ethereum', () => {

let WBGLSDKInstance: WBGLBridgeSDK
let provider: ethers.providers.JsonRpcProvider | ethers.providers.Web3Provider
import { ethers } from 'ethers';
import * as matchers from 'jest-extended';

import WBGLBridgeSDK, { ChaindIds, ChainNames, IBridgeConfig, WBGL } from '../';
import { WBGLBGLExchangePair } from '../bridge/WBGL';

expect.extend(matchers);

const hasBridgeIntegrationEnv =
process.env.RUN_BRIDGE_INTEGRATION_TESTS === 'true' &&
Boolean(process.env.EVM_PRIVATE_KEY) &&
Boolean(process.env.BGL_PRIVATEKEY_OR_SEED);
const describeBridgeIntegration = hasBridgeIntegrationEnv
? describe
: describe.skip;

describeBridgeIntegration('WBGL class tests on Ethereum', () => {
let WBGLSDKInstance: WBGLBridgeSDK;
let provider:
| ethers.providers.JsonRpcProvider
| ethers.providers.Web3Provider;
// const recepientWBGLAddress = ''
const bglAddress = 'bgl1qh3tsz3a7l3m49xaq4xcdx8aefthchuqagmspcn'
let bnbAddress: string
const bglAddress = 'bgl1qh3tsz3a7l3m49xaq4xcdx8aefthchuqagmspcn';
let bnbAddress: string;

beforeAll(async () => {
const bscProvider = 'https://rpc.ankr.com/bsc'
// const MNEMONIC = process.env.MNEMONIC
const bscProvider = 'https://rpc.ankr.com/bsc';
// const MNEMONIC = process.env.MNEMONIC

provider = new ethers.providers.JsonRpcProvider(bscProvider)
provider = new ethers.providers.JsonRpcProvider(bscProvider);

const config: IBridgeConfig = {
evmPrivateKey: process.env.EVM_PRIVATE_KEY as string,
provider: provider,
chainName: ChainNames.BNBSmartChain,
chainId: ChaindIds.BNBSmartChain,
bridgeEndpoint: 'https://bglswap.com/app/',
bglPrivateKeyOrSeed: process.env.BGL_PRIVATEKEY_OR_SEED as string
}

WBGLSDKInstance = new WBGLBridgeSDK(config)
const signer = new ethers.Wallet(config.evmPrivateKey, provider)
bnbAddress = await signer.getAddress()
})
bglPrivateKeyOrSeed: process.env.BGL_PRIVATEKEY_OR_SEED as string,
};

WBGLSDKInstance = new WBGLBridgeSDK(config);
const signer = new ethers.Wallet(config.evmPrivateKey, provider);
bnbAddress = await signer.getAddress();
});

it('test that WBGL instantiates correctly', () => {
expect(WBGLSDKInstance).toBeInstanceOf(WBGLBridgeSDK)
expect(WBGLSDKInstance.wbgl).toBeInstanceOf(WBGL)
})
expect(WBGLSDKInstance).toBeInstanceOf(WBGLBridgeSDK);
expect(WBGLSDKInstance.wbgl).toBeInstanceOf(WBGL);
});

it('should swap WBGL tokens for BGL via the Bridge', async () => {
// NOTE: this requires some ether/bnb to cover gas fees for WBGL token transfer
const wbglPair: WBGLBGLExchangePair = {
bglAddress: bglAddress,
to: bnbAddress,
wbglAmount: 5
}
const tx = await WBGLSDKInstance.wbgl.swapWBGLforBGL(wbglPair)
console.log(tx)
expect(tx.transactionHash).toBeDefined()
})

})
wbglAmount: 5,
};
const tx = await WBGLSDKInstance.wbgl.swapWBGLforBGL(wbglPair);
console.log(tx);
expect(tx.transactionHash).toBeDefined();
});
});
Loading