Skip to content

Commit

Permalink
test: add 'updateStreamBrokerFee' integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielstoica committed Aug 9, 2024
1 parent ed9f088 commit 9f1b4c1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/integration/Integration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { InvoiceModule } from "./../../src/modules/invoice-module/InvoiceModule.
import { SablierV2LockupLinear } from "@sablier/v2-core/src/SablierV2LockupLinear.sol";
import { SablierV2LockupTranched } from "@sablier/v2-core/src/SablierV2LockupTranched.sol";
import { NFTDescriptorMock } from "@sablier/v2-core/test/mocks/NFTDescriptorMock.sol";
import { MockStreamManager } from "../mocks/MockStreamManager.sol";

abstract contract Integration_Test is Base_Test {
/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -17,6 +18,7 @@ abstract contract Integration_Test is Base_Test {
NFTDescriptorMock internal mockNFTDescriptor;
SablierV2LockupLinear internal sablierV2LockupLinear;
SablierV2LockupTranched internal sablierV2LockupTranched;
MockStreamManager internal mockStreamManager;

/*//////////////////////////////////////////////////////////////////////////
SET-UP FUNCTION
Expand All @@ -35,6 +37,9 @@ abstract contract Integration_Test is Base_Test {
// Deploy the {Container} contract with the {InvoiceModule} enabled by default
container = deployContainer({ _owner: users.eve, _dockId: 0, _initialModules: modules });

// Deploy the mock {StreamManager}
mockStreamManager = new MockStreamManager(sablierV2LockupLinear, sablierV2LockupTranched, users.admin);

// Label the test contracts so we can easily track them
vm.label({ account: address(invoiceModule), newLabel: "InvoiceModule" });
vm.label({ account: address(sablierV2LockupLinear), newLabel: "SablierV2LockupLinear" });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import { Integration_Test } from "../../../Integration.t.sol";
import { Types } from "./../../../../../src/modules/invoice-module/libraries/Types.sol";
import { Errors } from "../../../../utils/Errors.sol";
import { Events } from "../../../../utils/Events.sol";
import { ud, UD60x18 } from "@prb/math/src/UD60x18.sol";

contract UpdateStreamBrokerFee_Integration_Concret_Test is Integration_Test {
Types.Invoice invoice;

function setUp() public virtual override {
Integration_Test.setUp();
}

function test_RevertWhen_CallerNotOwner() external {
// Make Bob the caller in this test suite who is not the broker admin
vm.startPrank({ msgSender: users.bob });

// Expect the call to revert with the {OnlyBrokerAdmin} error
vm.expectRevert(Errors.OnlyBrokerAdmin.selector);

// Run the test
mockStreamManager.updateStreamBrokerFee({ newBrokerFee: ud(0.05e18) });
}

modifier whenCallerBrokerAdmin() {
// Make Admin the caller in this test suite
vm.startPrank({ msgSender: users.admin });

_;
}

function test_UpdateStreamBrokerFee() external whenCallerBrokerAdmin {
UD60x18 newBrokerFee = ud(0.05e18);

// Expect the {BrokerFeeUpdated} to be emitted
vm.expectEmit();
emit Events.BrokerFeeUpdated({ oldFee: ud(0), newFee: newBrokerFee });

// Run the test
mockStreamManager.updateStreamBrokerFee(newBrokerFee);

// Assert the actual and expected broker fee
UD60x18 actualBrokerFee = mockStreamManager.brokerFee();
assertEq(UD60x18.unwrap(actualBrokerFee), UD60x18.unwrap(newBrokerFee));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
updateStreamBrokerFee.t.sol
├── when the caller IS NOT the broker admin
│ └── it should revert with the {OnlyBrokerAdmin} error
└── when the caller IS the broker admin
└── it should update the broker admin
└── it should emit a {BrokerFeeUpdated} event
16 changes: 16 additions & 0 deletions test/mocks/MockStreamManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.26;

import { StreamManager } from "./../../src/modules/invoice-module/sablier-v2/StreamManager.sol";
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
import { ISablierV2LockupTranched } from "@sablier/v2-core/src/interfaces/ISablierV2LockupTranched.sol";

/// @title MockStreamManager
/// @notice A mock implementation of the `StreamManager` contract
contract MockStreamManager is StreamManager {
constructor(
ISablierV2LockupLinear _sablierLockupLinear,
ISablierV2LockupTranched _sablierLockupTranched,
address _brokerAdmin
) StreamManager(_sablierLockupLinear, _sablierLockupTranched, _brokerAdmin) { }
}
6 changes: 6 additions & 0 deletions test/utils/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.26;
import { Types } from "./../../src/modules/invoice-module/libraries/Types.sol";
import { Container } from "./../../src/Container.sol";
import { ModuleKeeper } from "./../../src/ModuleKeeper.sol";
import { UD60x18 } from "@prb/math/src/UD60x18.sol";

/// @notice Abstract contract to store all the events emitted in the tested contracts
abstract contract Events {
Expand Down Expand Up @@ -100,6 +101,11 @@ abstract contract Events {
/// @param id The ID of the invoice
event InvoiceCanceled(uint256 indexed id);

/// @notice Emitted when the broker fee is updated
/// @param oldFee The old broker fee
/// @param newFee The new broker fee
event BrokerFeeUpdated(UD60x18 oldFee, UD60x18 newFee);

/*//////////////////////////////////////////////////////////////////////////
OWNABLE
//////////////////////////////////////////////////////////////////////////*/
Expand Down

0 comments on commit 9f1b4c1

Please sign in to comment.