Skip to content

Commit

Permalink
fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenSwen committed Sep 22, 2023
1 parent e4d462c commit d5e6e4f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
74 changes: 37 additions & 37 deletions test/FeeBank.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,60 +31,60 @@ describe('FeeBank', function () {
describe('deposits', function () {
it('should increase accountDeposits and availableCredit with deposit()', async function () {
const { contracts: { inch, feeBank }, accounts: { owner, alice } } = await loadFixture(initContracts);
const addrAmount = ether('1');
const ownerAmount = ether('1');
const aliceAmount = ether('10');
const addrbalanceBefore = await inch.balanceOf(owner.address);
const alicebalanceBefore = await inch.balanceOf(alice.address);
const ownerBalanceBefore = await inch.balanceOf(owner.address);
const aliceBalanceBefore = await inch.balanceOf(alice.address);

await feeBank.deposit(addrAmount);
await feeBank.deposit(ownerAmount);
await feeBank.connect(alice).deposit(aliceAmount);

expect(await feeBank.availableCredit(owner.address)).to.equal(addrAmount);
expect(await feeBank.availableCredit(owner.address)).to.equal(ownerAmount);
expect(await feeBank.availableCredit(alice.address)).to.equal(aliceAmount);
expect(await inch.balanceOf(owner.address)).to.equal(addrbalanceBefore.sub(addrAmount));
expect(await inch.balanceOf(alice.address)).to.equal(alicebalanceBefore.sub(aliceAmount));
expect(await inch.balanceOf(owner.address)).to.equal(ownerBalanceBefore.sub(ownerAmount));
expect(await inch.balanceOf(alice.address)).to.equal(aliceBalanceBefore.sub(aliceAmount));
});

it('should increase accountDeposits and availableCredit with depositFor()', async function () {
const { contracts: { inch, feeBank }, accounts: { owner, alice } } = await loadFixture(initContracts);
const addrAmount = ether('1');
const ownerAmount = ether('1');
const aliceAmount = ether('10');
const addrbalanceBefore = await inch.balanceOf(owner.address);
const alicebalanceBefore = await inch.balanceOf(alice.address);
const ownerBalanceBefore = await inch.balanceOf(owner.address);
const aliceBalanceBefore = await inch.balanceOf(alice.address);

await feeBank.connect(alice).depositFor(owner.address, addrAmount);
await feeBank.connect(alice).depositFor(owner.address, ownerAmount);
await feeBank.depositFor(alice.address, aliceAmount);

expect(await feeBank.availableCredit(owner.address)).to.equal(addrAmount);
expect(await feeBank.availableCredit(owner.address)).to.equal(ownerAmount);
expect(await feeBank.availableCredit(alice.address)).to.equal(aliceAmount);
expect(await inch.balanceOf(owner.address)).to.equal(addrbalanceBefore.sub(aliceAmount));
expect(await inch.balanceOf(alice.address)).to.equal(alicebalanceBefore.sub(addrAmount));
expect(await inch.balanceOf(owner.address)).to.equal(ownerBalanceBefore.sub(aliceAmount));
expect(await inch.balanceOf(alice.address)).to.equal(aliceBalanceBefore.sub(ownerAmount));
});

it('should increase accountDeposits and availableCredit without approve with depositWithPermit()', async function () {
const { contracts: { inch, feeBank }, accounts: { owner }, others: { chainId } } = await loadFixture(initContracts);
const addrAmount = ether('1');
const ownerAmount = ether('1');
await inch.approve(feeBank.address, '0');
const permit = await getPermit(owner, inch, '1', chainId, feeBank.address, addrAmount);
const addrbalanceBefore = await inch.balanceOf(owner.address);
const permit = await getPermit(owner, inch, '1', chainId, feeBank.address, ownerAmount);
const ownerBalanceBefore = await inch.balanceOf(owner.address);

await feeBank.depositWithPermit(addrAmount, permit);
await feeBank.depositWithPermit(ownerAmount, permit);

expect(await feeBank.availableCredit(owner.address)).to.equal(addrAmount);
expect(await inch.balanceOf(owner.address)).to.equal(addrbalanceBefore.sub(addrAmount));
expect(await feeBank.availableCredit(owner.address)).to.equal(ownerAmount);
expect(await inch.balanceOf(owner.address)).to.equal(ownerBalanceBefore.sub(ownerAmount));
});

it('should increase accountDeposits and availableCredit without approve with depositForWithPermit()', async function () {
const { contracts: { inch, feeBank }, accounts: { owner, alice }, others: { chainId } } = await loadFixture(initContracts);
const addrAmount = ether('1');
const ownerAmount = ether('1');
await inch.approve(feeBank.address, '0');
const permit = await getPermit(owner, inch, '1', chainId, feeBank.address, addrAmount);
const addrbalanceBefore = await inch.balanceOf(owner.address);
const permit = await getPermit(owner, inch, '1', chainId, feeBank.address, ownerAmount);
const ownerBalanceBefore = await inch.balanceOf(owner.address);

await feeBank.depositForWithPermit(alice.address, addrAmount, permit);
await feeBank.depositForWithPermit(alice.address, ownerAmount, permit);

expect(await feeBank.availableCredit(alice.address)).to.equal(addrAmount);
expect(await inch.balanceOf(owner.address)).to.equal(addrbalanceBefore.sub(addrAmount));
expect(await feeBank.availableCredit(alice.address)).to.equal(ownerAmount);
expect(await inch.balanceOf(owner.address)).to.equal(ownerBalanceBefore.sub(ownerAmount));
});
});

Expand All @@ -100,23 +100,23 @@ describe('FeeBank', function () {
it('should decrease accountDeposits and availableCredit with withdraw()', async function () {
const { contracts: { inch, feeBank }, accounts: { owner }, others: { totalDepositAmount } } = await loadFixture(initContratsAndDeposit);
const amount = ether('10');
const addrbalanceBefore = await inch.balanceOf(owner.address);
const ownerBalanceBefore = await inch.balanceOf(owner.address);

await feeBank.withdraw(amount);

expect(await feeBank.availableCredit(owner.address)).to.equal(totalDepositAmount - amount);
expect(await inch.balanceOf(owner.address)).to.equal(addrbalanceBefore.add(amount));
expect(await inch.balanceOf(owner.address)).to.equal(ownerBalanceBefore.add(amount));
});

it('should decrease accountDeposits and availableCredit with withdrawTo()', async function () {
const { contracts: { inch, feeBank }, accounts: { owner, alice }, others: { totalDepositAmount } } = await loadFixture(initContratsAndDeposit);
const amount = ether('10');
const alicebalanceBefore = await inch.balanceOf(alice.address);
const aliceBalanceBefore = await inch.balanceOf(alice.address);

await feeBank.withdrawTo(alice.address, amount);

expect(await feeBank.availableCredit(owner.address)).to.equal(totalDepositAmount - amount);
expect(await inch.balanceOf(alice.address)).to.equal(alicebalanceBefore.add(amount));
expect(await inch.balanceOf(alice.address)).to.equal(aliceBalanceBefore.add(amount));
});

it('should not withdrawal more than account have', async function () {
Expand All @@ -143,24 +143,24 @@ describe('FeeBank', function () {

it('should correct withdrawal fee for 2 account', async function () {
const { contracts: { inch, feeBank, matcher }, accounts: { owner, alice } } = await loadFixture(initContracts);
const addrAmount = ether('10');
const ownerAmount = ether('10');
const aliceAmount = ether('25');
const subCreditaddrAmount = ether('2');
const subCreditownerAmount = ether('2');
const subCreditaliceAmount = ether('11');
await feeBank.deposit(addrAmount);
await feeBank.deposit(ownerAmount);
await feeBank.connect(alice).deposit(aliceAmount);
await matcher.decreaseAvailableCreditMock(owner.address, subCreditaddrAmount);
await matcher.decreaseAvailableCreditMock(owner.address, subCreditownerAmount);
await matcher.decreaseAvailableCreditMock(alice.address, subCreditaliceAmount);

const balanceBefore = await inch.balanceOf(owner.address);
expect(await feeBank.availableCredit(owner.address)).to.equal(addrAmount - subCreditaddrAmount);
expect(await feeBank.availableCredit(owner.address)).to.equal(ownerAmount - subCreditownerAmount);
expect(await feeBank.availableCredit(alice.address)).to.equal(aliceAmount - subCreditaliceAmount);
await feeBank.gatherFees([owner.address, alice.address]);

expect(await feeBank.availableCredit(owner.address)).to.equal(addrAmount - subCreditaddrAmount);
expect(await feeBank.availableCredit(owner.address)).to.equal(ownerAmount - subCreditownerAmount);
expect(await feeBank.availableCredit(alice.address)).to.equal(aliceAmount - subCreditaliceAmount);
expect(await inch.balanceOf(owner.address)).to.equal(
balanceBefore.add(subCreditaddrAmount).add(subCreditaliceAmount),
balanceBefore.add(subCreditownerAmount).add(subCreditaliceAmount),
);
});

Expand Down
14 changes: 7 additions & 7 deletions test/Settlement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Settlement', function () {
async function initContracts() {
const abiCoder = ethers.utils.defaultAbiCoder;
const chainId = await getChainId();
const [owner, alice, addr2] = await ethers.getSigners();
const [owner, alice, bob] = await ethers.getSigners();

const { dai, weth, inch, swap } = await deploySwapTokens();

Expand All @@ -40,7 +40,7 @@ describe('Settlement', function () {

return {
contracts: { dai, weth, swap, settlement, feeBank, resolver },
accounts: { owner, alice, addr2 },
accounts: { owner, alice, bob },
others: { chainId, abiCoder },
};
}
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('Settlement', function () {
const dataFormFixture = await loadFixture(initContracts);
const {
contracts: { dai, weth, settlement, resolver },
accounts: { owner, alice, addr2 },
accounts: { owner, alice, bob },
} = dataFormFixture;

const fillOrderToData1 = await buildCalldataForOrder({
Expand All @@ -240,7 +240,7 @@ describe('Settlement', function () {
takingAmount: ether('100'),
makerTraits: buildMakerTraits({ allowedSender: settlement.address }),
},
singleFusionData: { resolvers: [resolver.address], takerFee: 10000000n, takerFeeReceiver: addr2.address },
singleFusionData: { resolvers: [resolver.address], takerFee: 10000000n, takerFeeReceiver: bob.address },
orderSigner: alice,
dataFormFixture,
isInnermostOrder: true,
Expand All @@ -255,7 +255,7 @@ describe('Settlement', function () {
takingAmount: ether('0.1'),
makerTraits: buildMakerTraits({ allowedSender: settlement.address }),
},
singleFusionData: { resolvers: [resolver.address], takerFee: 10000000n, takerFeeReceiver: addr2.address },
singleFusionData: { resolvers: [resolver.address], takerFee: 10000000n, takerFeeReceiver: bob.address },
orderSigner: owner,
dataFormFixture,
additionalDataForSettlement: fillOrderToData1,
Expand All @@ -269,8 +269,8 @@ describe('Settlement', function () {
await dai.connect(alice).transfer(resolver.address, daiFeeAmount.toString());

const txn = await resolver.settleOrders(fillOrderToData0);
await expect(txn).to.changeTokenBalances(dai, [owner, alice, addr2], [ether('-100'), ether('100'), ether('1')]);
await expect(txn).to.changeTokenBalances(weth, [owner, alice, addr2], [ether('0.1'), ether('-0.1'), ether('0.001')]);
await expect(txn).to.changeTokenBalances(dai, [owner, alice, bob], [ether('-100'), ether('100'), ether('1')]);
await expect(txn).to.changeTokenBalances(weth, [owner, alice, bob], [ether('0.1'), ether('-0.1'), ether('0.001')]);
});

it('unidirectional recursive swap', async function () {
Expand Down

0 comments on commit d5e6e4f

Please sign in to comment.