mirror of
https://github.com/status-im/eth_ava_bridge.git
synced 2025-02-22 15:58:14 +00:00
add deposit test
This commit is contained in:
parent
ea6095fd95
commit
fd7cb2165c
@ -3,7 +3,7 @@ pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../interfaces/IDepositExecute.sol";
|
||||
import "./HandlerHelpers.sol";
|
||||
import "../ERC20Safe.sol";
|
||||
import "../tokens/ERC20Safe.sol";
|
||||
|
||||
/**
|
||||
@title Handles ERC20 deposits and deposit executions.
|
||||
|
@ -97,7 +97,7 @@ contract ERC20Safe {
|
||||
@param token Token instance call targets
|
||||
@param data encoded call data
|
||||
*/
|
||||
function _safeCall(IERC20 token, bytes memory data) private {
|
||||
function _safeCall(IERC20 token, bytes memory data) private {
|
||||
(bool success, bytes memory returndata) = address(token).call(data);
|
||||
require(success, "ERC20: call failed");
|
||||
|
@ -1,11 +1,20 @@
|
||||
import { ethers } from "hardhat";
|
||||
import { ethers, } from "hardhat";
|
||||
import { Signer } from "ethers";
|
||||
import { expect } from "chai";
|
||||
import chai from "chai";
|
||||
import { solidity } from "ethereum-waffle";
|
||||
|
||||
import { Bridge } from "../types/Bridge"
|
||||
import { ERC20Handler } from "../types/ERC20Handler"
|
||||
import { MintableERC20 } from "../types/MintableERC20"
|
||||
import { createResourceID } from "../utils/helpers"
|
||||
import { Bridge } from "../types/Bridge";
|
||||
import { ERC20Handler } from "../types/ERC20Handler";
|
||||
import { MintableERC20 } from "../types/MintableERC20";
|
||||
import {
|
||||
createResourceID,
|
||||
toWei,
|
||||
createERCDepositData,
|
||||
generateDepositMetaData
|
||||
} from "../utils/helpers";
|
||||
|
||||
chai.use(solidity);
|
||||
const { expect } = chai;
|
||||
|
||||
describe("Bridge", function () {
|
||||
const ETHEREUM_CHAIN_ID: number = 1;
|
||||
@ -17,6 +26,8 @@ describe("Bridge", function () {
|
||||
let sntEthereum: MintableERC20;
|
||||
let sntEthereumResourceId: string;
|
||||
let deployerAddress: string;
|
||||
let depositerAddress: string;
|
||||
let recipientAddress: string;
|
||||
|
||||
beforeEach(async function () {
|
||||
accounts = await ethers.getSigners();
|
||||
@ -43,7 +54,29 @@ describe("Bridge", function () {
|
||||
[]
|
||||
) as ERC20Handler;
|
||||
erc20Handler = _erc20Handler;
|
||||
await bridge.adminSetResource(
|
||||
erc20Handler.address,
|
||||
sntEthereumResourceId,
|
||||
sntEthereum.address
|
||||
);
|
||||
});
|
||||
|
||||
it("Should deposit erc20 in bridge", async function () {});
|
||||
it("Should deposit erc20 into the bridge", async function () {
|
||||
const [deployer, depositer, recipient] = accounts;
|
||||
depositerAddress = await depositer.getAddress();
|
||||
recipientAddress = await recipient.getAddress();
|
||||
const sntDepositer = sntEthereum.connect(depositer);
|
||||
await sntEthereum.mint(depositerAddress, toWei("100"));
|
||||
await sntDepositer.approve(erc20Handler.address, toWei("1"));
|
||||
|
||||
const encodedMetaData = generateDepositMetaData(1, recipientAddress);
|
||||
const bridgeDepositer = bridge.connect(depositer);
|
||||
const deposit = bridgeDepositer.deposit(
|
||||
AVA_CHAIN_ID,
|
||||
sntEthereumResourceId,
|
||||
encodedMetaData
|
||||
);
|
||||
await expect(deposit)
|
||||
.to.emit(bridgeDepositer, 'Deposit');
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,11 @@
|
||||
import { utils } from "ethers";
|
||||
const { hexZeroPad, hexlify, keccak256, formatBytes32String } = utils;
|
||||
const {
|
||||
hexZeroPad,
|
||||
hexlify,
|
||||
formatBytes32String,
|
||||
} = utils;
|
||||
|
||||
const AbiCoder = new utils.AbiCoder;
|
||||
export const toHex = (covertThis: any, padding: number) => {
|
||||
return hexZeroPad(hexlify(covertThis), padding);
|
||||
};
|
||||
@ -9,3 +14,28 @@ export const createResourceID = (contractAddress: string, chainID: number) => {
|
||||
const str = chainID.toString() + contractAddress
|
||||
return formatBytes32String(str.slice(0, 31));
|
||||
};
|
||||
|
||||
export const abiEncode = (valueTypes: any[], values: any[]) => {
|
||||
return AbiCoder.encode(valueTypes, values)
|
||||
};
|
||||
|
||||
export const generateDepositMetaData = (amount: number, recipientAddress: string) => {
|
||||
const addressLength = 20;
|
||||
return abiEncode(
|
||||
['uint256', 'uint256', 'bytes'],
|
||||
[amount, addressLength, recipientAddress]
|
||||
);
|
||||
}
|
||||
|
||||
export const toWei = (x: string) => utils.parseEther(x);
|
||||
|
||||
export const createERCDepositData = (
|
||||
tokenAmountOrID: number,
|
||||
lenRecipientAddress: number,
|
||||
recipientAddress: string
|
||||
): string => {
|
||||
return '0x' +
|
||||
toHex(tokenAmountOrID, 32).substr(2) + // Token amount or ID to deposit (32 bytes)
|
||||
toHex(lenRecipientAddress, 32).substr(2) + // len(recipientAddress) (32 bytes)
|
||||
recipientAddress.substr(2); // recipientAddress (?? bytes)
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user