diff --git a/e2e-contracts/flatten-contracts.sh b/e2e-contracts/flatten-contracts.sh index bfc1703e1..257d8cb54 100755 --- a/e2e-contracts/flatten-contracts.sh +++ b/e2e-contracts/flatten-contracts.sh @@ -40,5 +40,7 @@ flatten brlc-token BRLCToken flatten brlc-periphery CardPaymentProcessor flatten brlc-periphery CashbackDistributor flatten brlc-pix-cashier PixCashier +flatten brlc-yield-streamer BalanceTracker +flatten brlc-yield-streamer YieldStreamer #flatten brlc-multisig MultiSigWallet #flatten compound-periphery CompoundAgent \ No newline at end of file diff --git a/e2e-contracts/integration/test/helpers/recompile.ts b/e2e-contracts/integration/test/helpers/recompile.ts new file mode 100644 index 000000000..e520edbe9 --- /dev/null +++ b/e2e-contracts/integration/test/helpers/recompile.ts @@ -0,0 +1,25 @@ +import fs from 'fs'; + +const BALANCE_TRACKER_FILENAME : string = 'contracts/BalanceTracker.flattened.sol'; + +export function readTokenAddressFromSource() : string { + let file = fs.readFileSync(BALANCE_TRACKER_FILENAME).toString(); + const regex = /address public constant TOKEN = address\((0x[0-9a-fA-F]{40})\);/ + const matches = file.match(regex) as RegExpMatchArray; + const tokenAddress = matches[1]; + return tokenAddress; +} + +export function replaceTokenAddress(oldAddress: string, newAddress: string) { + let file = fs.readFileSync(BALANCE_TRACKER_FILENAME).toString(); + if (oldAddress === newAddress) { + // nothing to do + return; + } + fs.writeFileSync(BALANCE_TRACKER_FILENAME, file.replace(oldAddress, newAddress), {flag: 'w'}); +} + +export function recompile() { + const execSync = require('child_process').execSync; + execSync('npx hardhat compile'); +} \ No newline at end of file diff --git a/e2e-contracts/integration/test/integration.ts b/e2e-contracts/integration/test/integration.ts index 8a218b353..b87119888 100644 --- a/e2e-contracts/integration/test/integration.ts +++ b/e2e-contracts/integration/test/integration.ts @@ -2,13 +2,15 @@ import { ethers, upgrades } from "hardhat"; import { expect } from "chai"; import { ContractFactory } from "ethers"; import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; -import { BRLCToken, CardPaymentProcessor, CashbackDistributor, PixCashier } from "../typechain-types"; +import { BRLCToken, BalanceTracker, CardPaymentProcessor, CashbackDistributor, PixCashier } from "../typechain-types"; +import { readTokenAddressFromSource, recompile, replaceTokenAddress } from "./helpers/recompile"; /* Contracts instances */ let brlCoin: BRLCToken; let pixCashier: PixCashier; let cashbackDistributor: CashbackDistributor; let cardPaymentProcessor: CardPaymentProcessor; +let balanceTracker: BalanceTracker; /* Signers and Wallets */ let deployer: SignerWithAddress; @@ -69,6 +71,19 @@ async function configureCardPaymentProcessor() { cardPaymentProcessor.enableCashback(); } +async function deployBalanceTracker() { + const tokenAddressInSource = readTokenAddressFromSource(); + if (tokenAddressInSource !== await brlCoin.getAddress()) { + replaceTokenAddress(tokenAddressInSource, await brlCoin.getAddress()); + recompile(); + } + + let balanceTrackerFactory: ContractFactory = await ethers.getContractFactory("BalanceTracker"); + let deployedProxy = await upgrades.deployProxy(balanceTrackerFactory.connect(deployer)); + await deployedProxy.waitForDeployment(); + balanceTracker = deployedProxy.connect(deployer) as BalanceTracker; +} + describe("Integration Test", function () { before(async function () { [deployer] = await ethers.getSigners(); @@ -106,6 +121,11 @@ describe("Integration Test", function () { await configureCardPaymentProcessor(); }); + it("Deploy BalanceTracker", async function () { + await deployBalanceTracker(); + expect(await balanceTracker.TOKEN()).to.equal(await brlCoin.getAddress()); + }); + describe("Scenario 1", function () { let alice = ethers.Wallet.createRandom().connect(ethers.provider);