Skip to content

Commit

Permalink
Added event check on test
Browse files Browse the repository at this point in the history
  • Loading branch information
computerphysicslab committed Jul 2, 2021
1 parent 6dec0cf commit b7bcb05
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,11 @@ contract LoanTokenSettingsLowerAdmin is AdvancedToken {
bool isPaused
) public {
require(msg.sender == pauser, "onlyPauser");
/// keccak256("iToken_FunctionPause")
bytes32 slot =
keccak256(
abi.encodePacked(
bytes4(keccak256(abi.encodePacked(funcId))), /// Function selector.
uint256(0xd46a704bc285dbd6ff5ad3863506260b1df02812f4f857c8cc852317a6ac64f2)
uint256(0xd46a704bc285dbd6ff5ad3863506260b1df02812f4f857c8cc852317a6ac64f2) /// keccak256("iToken_FunctionPause")
)
);
assembly {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ contract PreviousLoanTokenSettingsLowerAdmin is AdvancedTokenStorage {
string memory funcId, /// Example: "mint(uint256,uint256)" ,i.e. function signature.
bool isPaused
) public onlyAdmin {
// keccak256("iToken_FunctionPause")
bytes32 slot =
keccak256(
abi.encodePacked(
bytes4(keccak256(abi.encodePacked(funcId))), /// Function selector.
uint256(0xd46a704bc285dbd6ff5ad3863506260b1df02812f4f857c8cc852317a6ac64f2)
uint256(0xd46a704bc285dbd6ff5ad3863506260b1df02812f4f857c8cc852317a6ac64f2) /// keccak256("iToken_FunctionPause")
)
);
assembly {
Expand Down
20 changes: 16 additions & 4 deletions tests-js/loan-token/Administration.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { expect } = require("chai");
const { expectRevert, BN } = require("@openzeppelin/test-helpers");
const { expectRevert, BN, expectEvent } = require("@openzeppelin/test-helpers");
const TestToken = artifacts.require("TestToken");
const LoanTokenLogicStandard = artifacts.require("LoanTokenLogicStandard");
const LoanTokenSettingsLowerAdmin = artifacts.require("LoanTokenSettingsLowerAdmin");
Expand Down Expand Up @@ -124,7 +124,13 @@ contract("LoanTokenAdministration", (accounts) => {
// pause the given function and make sure the function can't be called anymore
let localLoanToken = await LoanTokenLogicStandard.at(loanToken.address);
await localLoanToken.setPauser(accounts[0]);
await localLoanToken.toggleFunctionPause(functionSignature, true);
let tx = await localLoanToken.toggleFunctionPause(functionSignature, true);

// Check event is properly emitted
await expectEvent.inTransaction(tx.receipt.rawLogs[0].transactionHash, LoanTokenLogicStandard, "ToggleFunctionPause", {
funcId: functionSignature,
isPaused: true,
});

await expectRevert(open_margin_trade_position(loanToken, RBTC, WRBTC, SUSD, accounts[1]), "unauthorized");

Expand All @@ -134,7 +140,14 @@ contract("LoanTokenAdministration", (accounts) => {
// reactivate the given function and make sure the function can be called again
localLoanToken = await LoanTokenLogicStandard.at(loanToken.address);
await localLoanToken.setPauser(accounts[0]);
await localLoanToken.toggleFunctionPause(functionSignature, false);
tx = await localLoanToken.toggleFunctionPause(functionSignature, false);

// Check event is properly emitted
await expectEvent.inTransaction(tx.receipt.rawLogs[0].transactionHash, LoanTokenLogicStandard, "ToggleFunctionPause", {
funcId: functionSignature,
isPaused: false,
});

await open_margin_trade_position(loanToken, RBTC, WRBTC, SUSD, accounts[1]);

// check if checkPause returns false
Expand All @@ -146,6 +159,5 @@ contract("LoanTokenAdministration", (accounts) => {
let localLoanToken = await LoanTokenLogicStandard.at(loanToken.address);
await expectRevert(localLoanToken.toggleFunctionPause("mint(address,uint256)", true, { from: accounts[1] }), "onlyPauser");
});

});
});

0 comments on commit b7bcb05

Please sign in to comment.