Skip to content

Commit

Permalink
Passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
austinborn committed Sep 13, 2023
1 parent 2e31ec1 commit 838e072
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 457 deletions.
46 changes: 17 additions & 29 deletions contracts/src/v0.8/llo-feeds/test/fee-manager/BaseFeeManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ contract BaseFeeManagerTest is Test {
native = new WERC20Mock();

feeManagerProxy = new FeeManagerProxy();
rewardManager = new RewardManager(getLinkAddress());
feeManager = new FeeManager(getLinkAddress(), getNativeAddress(), address(feeManagerProxy), address(rewardManager));
rewardManager = new RewardManager(address(link));
feeManager = new FeeManager(address(link), address(native), address(feeManagerProxy), address(rewardManager));

//link the feeManager to the proxy
feeManagerProxy.setFeeManager(feeManager);
Expand Down Expand Up @@ -156,7 +156,7 @@ contract BaseFeeManagerTest is Test {
// solium-disable-next-line no-unused-vars
function getFee(
bytes memory report,
IFeeManager.Quote memory quote,
address quote,
address subscriber
) public view returns (Common.Asset memory) {
//get the fee
Expand All @@ -167,7 +167,7 @@ contract BaseFeeManagerTest is Test {

function getReward(
bytes memory report,
IFeeManager.Quote memory quote,
address quote,
address subscriber
) public view returns (Common.Asset memory) {
//get the reward
Expand All @@ -178,7 +178,7 @@ contract BaseFeeManagerTest is Test {

function getAppliedDiscount(
bytes memory report,
IFeeManager.Quote memory quote,
address quote,
address subscriber
) public view returns (uint256) {
//get the reward
Expand Down Expand Up @@ -239,12 +239,12 @@ contract BaseFeeManagerTest is Test {
);
}

function getLinkQuote() public view returns (IFeeManager.Quote memory) {
return IFeeManager.Quote(getLinkAddress());
function getLinkQuote() public view returns (address) {
return address(link);
}

function getNativeQuote() public view returns (IFeeManager.Quote memory) {
return IFeeManager.Quote(getNativeAddress());
function getNativeQuote() public view returns (address) {
return address(native);
}

function withdraw(address assetAddress, address recipient, uint256 amount, address sender) public {
Expand Down Expand Up @@ -302,6 +302,7 @@ contract BaseFeeManagerTest is Test {
function ProcessFeeAsUser(
bytes memory payload,
address subscriber,
address tokenAddress,
uint256 wrappedNativeValue,
address sender
) public {
Expand All @@ -310,52 +311,47 @@ contract BaseFeeManagerTest is Test {
changePrank(sender);

//process the fee
feeManager.processFee{value: wrappedNativeValue}(payload, subscriber);
feeManager.processFee{value: wrappedNativeValue}(payload, abi.encode(tokenAddress), subscriber);

//change ProcessFeeAsUserback to the original address
changePrank(originalAddr);
}

function processFee(bytes memory payload, address subscriber, uint256 wrappedNativeValue) public {
function processFee(bytes memory payload, address subscriber, address feeAddress, uint256 wrappedNativeValue) public {
//record the current address and switch to the recipient
address originalAddr = msg.sender;
changePrank(subscriber);

//process the fee
feeManagerProxy.processFee{value: wrappedNativeValue}(payload);
feeManagerProxy.processFee{value: wrappedNativeValue}(payload, abi.encode(feeAddress));

//change back to the original address
changePrank(originalAddr);
}

function processFee(bytes[] memory payloads, address subscriber, uint256 wrappedNativeValue) public {
function processFee(bytes[] memory payloads, address subscriber, address feeAddress, uint256 wrappedNativeValue) public {
//record the current address and switch to the recipient
address originalAddr = msg.sender;
changePrank(subscriber);

//process the fee
feeManagerProxy.processFeeBulk{value: wrappedNativeValue}(payloads);
feeManagerProxy.processFeeBulk{value: wrappedNativeValue}(payloads, abi.encode(feeAddress));

//change back to the original address
changePrank(originalAddr);
}

function getPayload(bytes memory reportPayload, bytes memory quotePayload) public pure returns (bytes memory) {
function getPayload(bytes memory reportPayload) public pure returns (bytes memory) {
return
abi.encode(
[DEFAULT_CONFIG_DIGEST, 0, 0],
reportPayload,
new bytes32[](1),
new bytes32[](1),
bytes32(""),
quotePayload
bytes32("")
);
}

function getQuotePayload(address quoteAddress) public pure returns (bytes memory) {
return abi.encode(quoteAddress);
}

function approveLink(address spender, uint256 quantity, address sender) public {
//record the current address and switch to the recipient
address originalAddr = msg.sender;
Expand All @@ -380,14 +376,6 @@ contract BaseFeeManagerTest is Test {
changePrank(originalAddr);
}

function getLinkAddress() public view returns (address) {
return address(link);
}

function getNativeAddress() public view returns (address) {
return address(native);
}

function payLinkDeficit(bytes32 configDigest, address sender) public {
//record the current address and switch to the recipient
address originalAddr = msg.sender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract FeeManagerProcessFeeTest is BaseFeeManagerTest {
uint256 withdrawAmount = contractBalance / 2;

//withdraw some balance
withdraw(getLinkAddress(), ADMIN, withdrawAmount, ADMIN);
withdraw(address(link), ADMIN, withdrawAmount, ADMIN);

//check the balance has been reduced
uint256 newContractBalance = getLinkBalance(address(feeManager));
Expand Down Expand Up @@ -76,7 +76,7 @@ contract FeeManagerProcessFeeTest is BaseFeeManagerTest {
vm.expectRevert(ONLY_CALLABLE_BY_OWNER_ERROR);

//withdraw some balance
withdraw(getLinkAddress(), ADMIN, DEFAULT_LINK_MINT_QUANTITY, USER);
withdraw(address(link), ADMIN, DEFAULT_LINK_MINT_QUANTITY, USER);
}

function test_eventIsEmittedAfterSurchargeIsSet() public {
Expand All @@ -101,10 +101,10 @@ contract FeeManagerProcessFeeTest is BaseFeeManagerTest {
vm.expectEmit();

//emit the event that is expected to be emitted
emit SubscriberDiscountUpdated(USER, DEFAULT_FEED_1_V3, getNativeAddress(), discount);
emit SubscriberDiscountUpdated(USER, DEFAULT_FEED_1_V3, address(native), discount);

//set the surcharge
setSubscriberDiscount(USER, DEFAULT_FEED_1_V3, getNativeAddress(), discount, ADMIN);
setSubscriberDiscount(USER, DEFAULT_FEED_1_V3, address(native), discount, ADMIN);
}

function test_eventIsEmittedUponWithdraw() public {
Expand All @@ -118,10 +118,10 @@ contract FeeManagerProcessFeeTest is BaseFeeManagerTest {
vm.expectEmit();

//the event to be emitted
emit Withdraw(ADMIN, ADMIN, getLinkAddress(), withdrawAmount);
emit Withdraw(ADMIN, ADMIN, address(link), withdrawAmount);

//withdraw some balance
withdraw(getLinkAddress(), ADMIN, withdrawAmount, ADMIN);
withdraw(address(link), ADMIN, withdrawAmount, ADMIN);
}

function test_linkAvailableForPaymentReturnsLinkBalance() public {
Expand All @@ -137,7 +137,7 @@ contract FeeManagerProcessFeeTest is BaseFeeManagerTest {

function test_payLinkDeficit() public {
//get the default payload
bytes memory payload = getPayload(getV2Report(DEFAULT_FEED_1_V3), getQuotePayload(getNativeAddress()));
bytes memory payload = getPayload(getV2Report(DEFAULT_FEED_1_V3));

approveNative(address(feeManager), DEFAULT_REPORT_NATIVE_FEE, USER);

Expand All @@ -150,7 +150,7 @@ contract FeeManagerProcessFeeTest is BaseFeeManagerTest {
emit InsufficientLink(contractFees);

//process the fee
processFee(payload, USER, 0);
processFee(payload, USER, address(native), 0);

//double check the rewardManager balance is 0
assertEq(getLinkBalance(address(rewardManager)), 0);
Expand All @@ -170,7 +170,7 @@ contract FeeManagerProcessFeeTest is BaseFeeManagerTest {

function test_payLinkDeficitTwice() public {
//get the default payload
bytes memory payload = getPayload(getV2Report(DEFAULT_FEED_1_V3), getQuotePayload(getNativeAddress()));
bytes memory payload = getPayload(getV2Report(DEFAULT_FEED_1_V3));

approveNative(address(feeManager), DEFAULT_REPORT_NATIVE_FEE, USER);

Expand All @@ -184,7 +184,7 @@ contract FeeManagerProcessFeeTest is BaseFeeManagerTest {
emit InsufficientLink(contractFees);

//process the fee
processFee(payload, USER, 0);
processFee(payload, USER, address(native), 0);

//double check the rewardManager balance is 0
assertEq(getLinkBalance(address(rewardManager)), 0);
Expand All @@ -209,14 +209,14 @@ contract FeeManagerProcessFeeTest is BaseFeeManagerTest {

function test_payLinkDeficitPaysAllFeesProcessed() public {
//get the default payload
bytes memory payload = getPayload(getV2Report(DEFAULT_FEED_1_V3), getQuotePayload(getNativeAddress()));
bytes memory payload = getPayload(getV2Report(DEFAULT_FEED_1_V3));

//approve the native to be transferred from the user
approveNative(address(feeManager), DEFAULT_REPORT_NATIVE_FEE * 2, USER);

//processing the fee will transfer the native from the user to the feeManager
processFee(payload, USER, 0);
processFee(payload, USER, 0);
processFee(payload, USER, address(native), 0);
processFee(payload, USER, address(native), 0);

//check the deficit has been increased twice
assertEq(getLinkDeficit(DEFAULT_CONFIG_DIGEST), DEFAULT_REPORT_LINK_FEE * 2);
Expand Down
Loading

0 comments on commit 838e072

Please sign in to comment.