Add test for TransactionHandlle throwing
@@ -9,6 +9,15 @@ import { ethers, utils, Contract } from "ethers";
import {parseEther} from "ethers/utils";
+const WEB3_URL = process.env.WEB3_URL;
+// Mnemonic for eth wallet.
+const MNEMONIC = process.env.TEST_MNEMONIC;
+const ERC_20TOKEN = process.env.TEST_ERC20;
+
+const network = process.env.ETH_NETWORK == "localhost" ? "localhost" : "testnet";
+console.log("Running integration test on the ", network, " network");
+const ethersProvider = new ethers.providers.JsonRpcProvider(WEB3_URL);
+
let syncProvider: Provider;
async function getOperatorBalance(token: types.TokenLike, type: "committed" | "verified" = "committed") {
@@ -165,6 +174,47 @@ async function testChangePubkeyOffchain(syncWallet: Wallet) {
}
}
+async function testThrowingErrorOnTxFail(syncWalletRich: Wallet) {
+ let testPassed = true;
+
+ const ethWallet = ethers.Wallet.createRandom().connect(ethersProvider);
+ const syncWallet = await Wallet.fromEthSigner(
+ ethWallet,
+ syncProvider,
+ );
+
+ try {
+ const tx = await syncWalletRich.depositToSyncFromEthereum({
+ depositTo: syncWallet.address(),
+ token: "ETH",
+ amount: utils.parseEther('0.01'),
+ maxFeeInETHToken: utils.parseEther('0'),
+ approveDepositAmountForERC20: true,
+ });
+ await tx.awaitVerifyReceipt();
+ testPassed = false;
+ } catch (e) {
+ console.log(`Error (expected) on priorityop fail:${e}`.slice(0,50));
+ }
+
+ try {
+ const tx = await syncWallet.syncTransfer({
+ to: syncWalletRich.address(),
+ token: "ETH",
+ amount: utils.parseEther('0.01'),
+ fee: utils.parseEther('10'),
+ });
+ await tx.awaitVerifyReceipt();
+ testPassed = false;
+ } catch (e) {
+ console.log('Error (expected) on sync tx fail:', e);
+ }
+
+ if (!testPassed) {
+ throw new Error("testThrowingErrorOnTxFail failed");
+ }
+}
+
async function moveFunds(contract: Contract, ethProxy: ETHProxy, depositWallet: Wallet, syncWallet1: Wallet, syncWallet2: Wallet, token: types.TokenLike, depositAmountETH: string) {
const depositAmount = utils.parseEther(depositAmountETH);
@@ -193,17 +243,8 @@ async function moveFunds(contract: Contract, ethProxy: ETHProxy, depositWallet:
(async () => {
try {
- const WEB3_URL = process.env.WEB3_URL;
- // Mnemonic for eth wallet.
- const MNEMONIC = process.env.TEST_MNEMONIC;
- const ERC_20TOKEN = process.env.TEST_ERC20;
-
- const network = process.env.ETH_NETWORK == "localhost" ? "localhost" : "testnet";
- console.log("Running integration test on the ", network, " network");
-
syncProvider = await Provider.newWebsocketProvider(process.env.WS_API_ADDR);
- const ethersProvider = new ethers.providers.JsonRpcProvider(WEB3_URL);
const ethProxy = new ETHProxy(ethersProvider, syncProvider.contractAddress);
const ethWallet = ethers.Wallet.fromMnemonic(
@@ -239,6 +280,8 @@ async function moveFunds(contract: Contract, ethProxy: ETHProxy, depositWallet:
syncProvider,
);
+ await testThrowingErrorOnTxFail(syncWalletRich);
+
await moveFunds(contract, ethProxy, syncWalletRich, syncWallet, syncWallet2, ERC_20TOKEN, "0.018");
await moveFunds(contract, ethProxy, syncWalletRich, syncWallet, syncWallet3, "ETH", "0.018");
