Skip to content

Commit

Permalink
add balance tracker deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
mayconamaroCW committed Mar 14, 2024
1 parent e705577 commit e27fb5c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions e2e-contracts/flatten-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions e2e-contracts/integration/test/helpers/recompile.ts
Original file line number Diff line number Diff line change
@@ -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');
}
22 changes: 21 additions & 1 deletion e2e-contracts/integration/test/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e27fb5c

Please sign in to comment.