Skip to content

Commit

Permalink
Emit events for cooldown, expiration and nonce changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Nov 1, 2023
1 parent 2c56e35 commit 708760c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
19 changes: 13 additions & 6 deletions contracts/Delay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ contract Delay is Modifier {
address indexed avatar,
address target
);
event TxCooldownSet(uint256 cooldown);
event TxExpirationSet(uint256 expiration);
event TxNonceSet(uint256 nonce);
event TransactionAdded(
uint256 indexed queueNonce,
bytes32 indexed txHash,
Expand Down Expand Up @@ -75,17 +78,19 @@ contract Delay is Modifier {
target = _target;
txExpiration = _expiration;
txCooldown = _cooldown;

setupModules();

emit DelaySetup(msg.sender, _owner, _avatar, _target);
emit AvatarSet(address(0), _avatar);
emit TargetSet(address(0), _target);
}

/// @dev Sets the cooldown before a transaction can be executed.
/// @param cooldown Cooldown in seconds that should be required before the transaction can be executed
/// @notice This can only be called by the owner
function setTxCooldown(uint256 cooldown) public onlyOwner {
txCooldown = cooldown;
emit TxCooldownSet(cooldown);
}

/// @dev Sets the duration for which a transaction is valid.
Expand All @@ -98,18 +103,20 @@ contract Delay is Modifier {
"Expiration must be 0 or at least 60 seconds"
);
txExpiration = expiration;
emit TxExpirationSet(expiration);
}

/// @dev Sets transaction nonce. Used to invalidate or skip transactions in queue.
/// @param _nonce New transaction nonce
/// @param nonce New transaction nonce
/// @notice This can only be called by the owner
function setTxNonce(uint256 _nonce) public onlyOwner {
function setTxNonce(uint256 nonce) public onlyOwner {
require(
_nonce > txNonce,
nonce > txNonce,
"New nonce must be higher than current txNonce"
);
require(_nonce <= queueNonce, "Cannot be higher than queueNonce");
txNonce = _nonce;
require(nonce <= queueNonce, "Cannot be higher than queueNonce");
txNonce = nonce;
emit TxNonceSet(nonce);
}

/// @dev Adds a transaction to the queue (same as avatar interface so that this can be placed between other modules and the avatar).
Expand Down
6 changes: 6 additions & 0 deletions contracts/test/TestFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;

import {ModuleProxyFactory} from "@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol";

contract TestFactory is ModuleProxyFactory {}
43 changes: 42 additions & 1 deletion test/Delay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ZeroState =
const ZeroAddress = '0x0000000000000000000000000000000000000000'
const FirstAddress = '0x0000000000000000000000000000000000000001'

describe.only('DelayModifier', async () => {
describe('DelayModifier', async () => {
const cooldown = 180
const expiration = 180 * 1000

Expand Down Expand Up @@ -199,6 +199,19 @@ describe.only('DelayModifier', async () => {
await avatar.exec(await modifier.getAddress(), 0, tx.data)
expect(await modifier.txCooldown()).to.equal(nextCooldown)
})

it('emits event SetTxCooldown', async () => {
const { avatar, modifier } = await loadFixture(setup)

const nextCooldown = 43
const tx = await modifier.setTxCooldown.populateTransaction(
BigInt(nextCooldown)
)

await expect(await avatar.exec(await modifier.getAddress(), 0, tx.data))
.to.emit(modifier, 'TxCooldownSet')
.withArgs(nextCooldown)
})
})

describe('setTxExpiration()', async () => {
Expand Down Expand Up @@ -231,6 +244,18 @@ describe.only('DelayModifier', async () => {

await expect(await modifier.txExpiration()).to.be.equals(nextExpiration)
})

it('it emits event TxExpirationSet', async () => {
const { avatar, modifier } = await loadFixture(setup)

const nextExpiration = 180000
const tx =
await modifier.setTxExpiration.populateTransaction(nextExpiration)

await expect(await avatar.exec(await modifier.getAddress(), 0, tx.data))
.to.emit(modifier, 'TxExpirationSet')
.withArgs(nextExpiration)
})
})

describe('setTxNonce()', async () => {
Expand Down Expand Up @@ -279,6 +304,22 @@ describe.only('DelayModifier', async () => {
expect(await avatar.exec(await modifier.getAddress(), 0, tx2.data))
expect(await modifier.txNonce()).to.be.equals(1)
})

it('it emits TxNonceSet', async () => {
const [user1] = await hre.ethers.getSigners()
const { avatar, modifier } = await loadFixture(setup)

const tx1 = await modifier.enableModule.populateTransaction(user1.address)
const tx2 = await modifier.setTxNonce.populateTransaction(1)

expect(await modifier.txNonce()).to.be.equals(0)
await avatar.exec(await modifier.getAddress(), 0, tx1.data)
await modifier.execTransactionFromModule(user1.address, 0, '0x', 0)

await expect(await avatar.exec(await modifier.getAddress(), 0, tx2.data))
.to.emit(modifier, 'TxNonceSet')
.withArgs(1)
})
})

describe('execTransactionFromModule()', async () => {
Expand Down

0 comments on commit 708760c

Please sign in to comment.