Skip to content

Commit

Permalink
Merge pull request #33 from bitfinity-network/develop
Browse files Browse the repository at this point in the history
Make envs optional
  • Loading branch information
alexshelkov authored Jul 18, 2024
2 parents 5be3b0e + 4421aed commit 3437c08
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 99 deletions.
6 changes: 6 additions & 0 deletions .changeset/breezy-squids-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@bitfinity-network/bridge": minor
"@bitfinity-network/bridge-widget": minor
---

Make envs optional
40 changes: 22 additions & 18 deletions packages/bridge/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,32 @@ export const IC_HOST = str.parse(
process.env.IC_HOST || 'http://127.0.0.1:4943'
);

export const FEE_CHARGE_ADDRESS = str.parse(process.env.FEE_CHARGE_ADDRESS);
export const FEE_CHARGE_ADDRESS = str
.optional()
.parse(process.env.FEE_CHARGE_ADDRESS);

export const ICRC2_MINTER_CANISTER_ID = str.parse(
process.env.ICRC2_MINTER_CANISTER_ID
);
export const ICRC2_MINTER_CANISTER_ID = str
.optional()
.parse(process.env.ICRC2_MINTER_CANISTER_ID);

export const ICRC2_TOKEN_CANISTER_ID = str.parse(
process.env.ICRC2_TOKEN_CANISTER_ID
);
export const ICRC2_TOKEN_CANISTER_ID = str
.optional()
.parse(process.env.ICRC2_TOKEN_CANISTER_ID);

export const BTC_BRIDGE_CANISTER_ID = str.parse(
process.env.BTC_BRIDGE_CANISTER_ID
);
export const BTC_BRIDGE_CANISTER_ID = str
.optional()
.parse(process.env.BTC_BRIDGE_CANISTER_ID);

export const RUNE_BRIDGE_CANISTER_ID = str.parse(
process.env.RUNE_BRIDGE_CANISTER_ID
);
export const RUNE_BRIDGE_CANISTER_ID = str
.optional()
.parse(process.env.RUNE_BRIDGE_CANISTER_ID);

export const RUNE_TOKEN_ID = str.parse(process.env.RUNE_TOKEN_ID);
export const RUNE_TOKEN_ID = str.optional().parse(process.env.RUNE_TOKEN_ID);

export const BFT_ETH_ADDRESS = str.parse(process.env.BFT_ETH_ADDRESS);
export const BFT_ETH_ADDRESS = str
.optional()
.parse(process.env.BFT_ETH_ADDRESS);

export const BTC_TOKEN_WRAPPED_ADDRESS = str.parse(
process.env.BTC_TOKEN_WRAPPED_ADDRESS
);
export const BTC_TOKEN_WRAPPED_ADDRESS = str
.optional()
.parse(process.env.BTC_TOKEN_WRAPPED_ADDRESS);
79 changes: 0 additions & 79 deletions packages/bridge/src/tests/btc.test.ts

This file was deleted.

100 changes: 100 additions & 0 deletions packages/bridge/src/tests/icrc2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { describe, expect, test } from 'vitest';

import { Connector, ICRC2_TOKEN_CANISTER_ID } from '../';
import {
createAgent,
createBitfinityWallet,
execSendIcrcToken,
mintNativeToken,
randomWallet,
testNetwork
} from './utils';
import { wait } from '../utils';

describe.sequential(
'icrc2',
async () => {
const wallet = randomWallet();

const { agent, identity } = createAgent(wallet.privateKey);
const bitfinityWallet = createBitfinityWallet(agent);

await mintNativeToken(wallet.address, '1000000000000000000');
await execSendIcrcToken(identity.getPrincipal().toText(), 100000000);
await wait(3000);

const connector = Connector.create();

connector.connectEthWallet(wallet);
connector.connectBitfinityWallet(bitfinityWallet);

connector.addNetwork(testNetwork);

const icrcBricdge = connector.getBridge('devnet', 'icrc_evm');

test('deploy icrc2 token to evm', async () => {
const wrapped = await icrcBricdge.deployWrappedToken({
id: ICRC2_TOKEN_CANISTER_ID,
name: 'AUX',
symbol: 'AUX'
});
expect(wrapped).toBeTypeOf('string');

const balance = await icrcBricdge.getWrappedTokenBalance(
wrapped,
wallet.address
);
expect(balance).toStrictEqual(0n);
});

test('bridge icrc2 token to evm', async () => {
const amount = 100000n;

await icrcBricdge.bridgeToEvmc({
token: ICRC2_TOKEN_CANISTER_ID,
owner: identity.getPrincipal().toText(),
recipient: wallet.address,
amount
});

await wait(10000);

const wrapped = await icrcBricdge.getWrappedTokenAddress(
ICRC2_TOKEN_CANISTER_ID
);

const balance = await icrcBricdge.getWrappedTokenBalance(
wrapped,
wallet.address
);
expect(balance).toStrictEqual(amount);
});

test('bridge evmc tokens to icrc2', async () => {
const amount = 1000n;

const balance = await icrcBricdge.getBaseTokenBalance(
ICRC2_TOKEN_CANISTER_ID,
identity.getPrincipal().toText()
);
expect(balance).toStrictEqual(99899980n);

const wrapped = await icrcBricdge.getWrappedTokenAddress(
ICRC2_TOKEN_CANISTER_ID
);

await icrcBricdge.bridgeFromEvmc({
wrappedToken: wrapped,
recipient: identity.getPrincipal().toText(),
amount
});

const balance2 = await icrcBricdge.getBaseTokenBalance(
ICRC2_TOKEN_CANISTER_ID,
identity.getPrincipal().toText()
);
expect(balance2).toStrictEqual(99900970n);
});
},
280000
);
4 changes: 2 additions & 2 deletions packages/widget/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export const LIST_URLS: ListsUrl[] = IS_DEV
}
];

export const IC_HOST = z.string().parse(process.env.IC_HOST);
export const RPC_URL = z.string().parse(process.env.RPC_URL);
export const IC_HOST = z.string().default('http://127.0.0.1:4943').parse(process.env.IC_HOST);
export const RPC_URL = z.string().default('http://127.0.0.1:8545').parse(process.env.RPC_URL);

const nativeCurrency = {
name: 'Bitfinity',
Expand Down

0 comments on commit 3437c08

Please sign in to comment.