The first file above shows the process of setting supported institutions twice and the second file is the stack trace that validated the duplication of institution in the array of institution
Created
March 4, 2024 06:48
-
-
Save Falilah/00055748981dda360dc8741d8f2b0579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.13; | |
import {Test, console2} from "forge-std/Test.sol"; | |
import {Paycrest} from "../../contracts/Paycrest.sol"; | |
import {PaycrestSettingManager} from "../../contracts/PaycrestSettingManager.sol"; | |
import {SharedStructs} from "../../contracts/libraries/SharedStructs.sol"; | |
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | |
import {MockUSDT} from "../../contracts/mocks/MockUSDC.sol"; | |
contract testPaycrest is Test{ | |
Paycrest paycrest; | |
ERC1967Proxy proxy; | |
address owner = makeAddr("Owner"); | |
address treasury = makeAddr("treasury"); | |
address aggregator = makeAddr("aggregator"); | |
MockUSDT Usdt; | |
function setUp() public{ | |
vm.startPrank(owner); | |
paycrest = new Paycrest(); | |
proxy = new ERC1967Proxy(address(paycrest), ""); | |
paycrest = Paycrest(address(proxy)); | |
paycrest.initialize(); | |
vm.stopPrank(); | |
Usdt = new MockUSDT(); | |
} | |
function testOwnerLogic() public{ | |
address own = paycrest.owner(); | |
assertEq(own, owner); | |
vm.startPrank(owner); | |
paycrest.settingManagerBool("token", address(Usdt), true); | |
SharedStructs.Institution memory institution = SharedStructs.Institution("ABNGNGLA","ACCESS BANK"); | |
SharedStructs.Institution memory institution2 = SharedStructs.Institution("DBLNNGLA","DIAMOND BANK"); | |
SharedStructs.Institution[] memory institutions = new SharedStructs.Institution[](2); | |
institutions[0] = institution; | |
institutions[1] = institution2; | |
paycrest.setSupportedInstitutions("NGN", institutions); | |
paycrest.updateProtocolFees(2); | |
paycrest.updateProtocolAddresses("treasury", treasury); | |
paycrest.updateProtocolAddresses("aggregator", aggregator); | |
vm.stopPrank(); | |
} | |
function testpartOrderSettle() external{ | |
testOwnerLogic(); | |
Usdt.approve(address(paycrest), 300_000e18); | |
address _senderFeeRecipient = makeAddr("_senderFeeRecipient"); | |
address _refundAddress = makeAddr("_refundAddress"); | |
address liquidityProvider = makeAddr("LiquidtyProvider"); | |
string memory messageHash = "09090990901 ACCESS BANK Jeff Dean"; | |
assertEq(Usdt.balanceOf(address(paycrest)), 0); | |
uint fullOrderAmount = 200_000e18; | |
bytes32 id = paycrest.createOrder(address(Usdt), fullOrderAmount, "ABNGNGLA", "to mother", 1_500, _senderFeeRecipient, 0, _refundAddress, messageHash); | |
//Aggregator settle 50% of the order | |
vm.startPrank(aggregator); | |
paycrest.settle("", id, "to mother", liquidityProvider, 50_000); | |
// assert balance left in paycrest is 0 usdt after settling 50% of the order leaving protocol fee and sender fee in the contract with no funds to settle other part of the order | |
//get the value of fee based on the percentage set | |
uint protocolfee = (fullOrderAmount * 2) / 100_000; | |
assertEq(Usdt.balanceOf(address(paycrest)), protocolfee); | |
// assert liquidty provider got the full amount of settling part payment of the order excluding the protocol fee. | |
// get protocol fee | |
assertEq(Usdt.balanceOf(liquidityProvider), (fullOrderAmount - protocolfee)); | |
} | |
function testDuplicatedInstitution() public{ | |
vm.startPrank(owner); | |
SharedStructs.Institution memory institution = SharedStructs.Institution("ABNGNGLA","ACCESS BANK"); | |
SharedStructs.Institution memory institution2 = SharedStructs.Institution("DBLNNGLA","DIAMOND BANK"); | |
SharedStructs.Institution[] memory institutions = new SharedStructs.Institution[](2); | |
institutions[0] = institution; | |
institutions[1] = institution2; | |
paycrest.setSupportedInstitutions("NGN", institutions); | |
SharedStructs.Institution[] memory institutionget = paycrest.getSupportedInstitutions("NGN"); | |
//assert institution return 2 as length | |
assertEq(institutionget.length, 2); | |
// next round of addition | |
SharedStructs.Institution memory institutionAccess = SharedStructs.Institution("ABNGNGLA","ACCESS BANK"); | |
SharedStructs.Institution memory institutionDiamond = SharedStructs.Institution("DBLNNGLA","DIAMOND BANK"); | |
SharedStructs.Institution memory institutionWema = SharedStructs.Institution("wemNNGLA","WEMA BANK"); | |
SharedStructs.Institution memory institutionOpay = SharedStructs.Institution("OPYNNGLA","OPAY BANK"); | |
SharedStructs.Institution[] memory institutionUpdate = new SharedStructs.Institution[](4); | |
institutionUpdate[0] = institutionAccess; | |
institutionUpdate[1] = institutionDiamond; | |
institutionUpdate[2] = institutionWema; | |
institutionUpdate[3] = institutionOpay; | |
paycrest.setSupportedInstitutions("NGN", institutionUpdate); | |
vm.stopPrank(); | |
SharedStructs.Institution[] memory institutionget2 = paycrest.getSupportedInstitutions("NGN"); | |
// assert the length increase after addition of 4 institutions which also include the duplication of the institutions added earlier | |
assertEq(institutionget2.length, 6); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[506435] testPaycrest::testDuplicatedInstitution() | |
├─ [0] VM::startPrank(Owner: [0x93B07479cC807d037A98B6bB122CE8201958a595]) | |
│ └─ ← () | |
├─ [208668] ERC1967Proxy::setSupportedInstitutions(0x4e474e0000000000000000000000000000000000000000000000000000000000, [Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 })]) | |
│ ├─ [203740] Paycrest::setSupportedInstitutions(0x4e474e0000000000000000000000000000000000000000000000000000000000, [Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 })]) [delegatecall] | |
│ │ └─ ← () | |
│ └─ ← () | |
├─ [2947] ERC1967Proxy::getSupportedInstitutions(0x4e474e0000000000000000000000000000000000000000000000000000000000) [staticcall] | |
│ ├─ [2525] Paycrest::getSupportedInstitutions(0x4e474e0000000000000000000000000000000000000000000000000000000000) [delegatecall] | |
│ │ └─ ← [Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 })] | |
│ └─ ← [Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 })] | |
├─ [271211] ERC1967Proxy::setSupportedInstitutions(0x4e474e0000000000000000000000000000000000000000000000000000000000, [Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 }), Institution({ code: 0x77656d4e4e474c41000000000000000000000000000000000000000000000000, name: 0x57454d412042414e4b0000000000000000000000000000000000000000000000 }), Institution({ code: 0x4f50594e4e474c41000000000000000000000000000000000000000000000000, name: 0x4f5041592042414e4b0000000000000000000000000000000000000000000000 })]) | |
│ ├─ [270759] Paycrest::setSupportedInstitutions(0x4e474e0000000000000000000000000000000000000000000000000000000000, [Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 }), Institution({ code: 0x77656d4e4e474c41000000000000000000000000000000000000000000000000, name: 0x57454d412042414e4b0000000000000000000000000000000000000000000000 }), Institution({ code: 0x4f50594e4e474c41000000000000000000000000000000000000000000000000, name: 0x4f5041592042414e4b0000000000000000000000000000000000000000000000 })]) [delegatecall] | |
│ │ └─ ← () | |
│ └─ ← () | |
├─ [0] VM::stopPrank() | |
│ └─ ← () | |
├─ [6204] ERC1967Proxy::getSupportedInstitutions(0x4e474e0000000000000000000000000000000000000000000000000000000000) [staticcall] | |
│ ├─ [5734] Paycrest::getSupportedInstitutions(0x4e474e0000000000000000000000000000000000000000000000000000000000) [delegatecall] | |
│ │ └─ ← [Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 }), Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 }), Institution({ code: 0x77656d4e4e474c41000000000000000000000000000000000000000000000000, name: 0x57454d412042414e4b0000000000000000000000000000000000000000000000 }), Institution({ code: 0x4f50594e4e474c41000000000000000000000000000000000000000000000000, name: 0x4f5041592042414e4b0000000000000000000000000000000000000000000000 })] | |
│ └─ ← [Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 }), Institution({ code: 0x41424e474e474c41000000000000000000000000000000000000000000000000, name: 0x4143434553532042414e4b000000000000000000000000000000000000000000 }), Institution({ code: 0x44424c4e4e474c41000000000000000000000000000000000000000000000000, name: 0x4449414d4f4e442042414e4b0000000000000000000000000000000000000000 }), Institution({ code: 0x77656d4e4e474c41000000000000000000000000000000000000000000000000, name: 0x57454d412042414e4b0000000000000000000000000000000000000000000000 }), Institution({ code: 0x4f50594e4e474c41000000000000000000000000000000000000000000000000, name: 0x4f5041592042414e4b0000000000000000000000000000000000000000000000 })] | |
└─ ← () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment