Skip to content

Commit

Permalink
chore: remove _lastValidateTime initialization in constructor (#493)
Browse files Browse the repository at this point in the history
* chore: remove _lastValidateTime initialization in constructor

* chore: update stateful tests

* chore: small update

* chore: reintroduce nzKey

* chore: fix flakyness
  • Loading branch information
albert-llimos authored Feb 12, 2024
1 parent 3813b43 commit faaedad
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 36 deletions.
1 change: 0 additions & 1 deletion contracts/KeyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ contract KeyManager is SchnorrSECP256K1, Shared, IKeyManager {
_aggKey = initialAggKey;
_govKey = initialGovKey;
_commKey = initialCommKey;
_lastValidateTime = block.timestamp;
}

//////////////////////////////////////////////////////////////
Expand Down
18 changes: 0 additions & 18 deletions tests/integration/keyManager/test_setKey_setKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ def test_setAggKeyWithAggKey_setAggKeyWithAggKey(cf):


def test_setGovKeyWithGovKey_setAggKeyWithGovKey(cf):
# Changing the agg key with the gov key should fail if the delay hasn't been long enough yet
# No time has passed since the constructor has set the first value of _lastValidateTime
with reverts(REV_MSG_DELAY):
cf.keyManager.setAggKeyWithGovKey(
AGG_SIGNER_2.getPubData(), {"from": cf.GOVERNOR_2}
)

chain.sleep(AGG_KEY_TIMEOUT)

# Change the gov key
setGovKeyWithGovKey_test(cf)

Expand All @@ -63,15 +54,6 @@ def test_setGovKeyWithGovKey_setAggKeyWithGovKey(cf):

# Check that _withAggKey calls update the _lastValidateTime
def test_setAggKeyWithGovKey_setKeyWithAggKey(cf):
# Changing the agg key with the gov key should fail if the delay hasn't been long enough yet
# No time has passed since the constructor has set the first value of _lastValidateTime
with reverts(REV_MSG_DELAY):
cf.keyManager.setAggKeyWithGovKey(
AGG_SIGNER_2.getPubData(), {"from": cf.GOVERNOR}
)

chain.sleep(AGG_KEY_TIMEOUT)

setAggKeyWithAggKey_test(cf)

# Reverts due to setAggKeyWithAggKey updating the _lastValidateTime
Expand Down
4 changes: 2 additions & 2 deletions tests/stateful/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def setup(self):
self.v_suspended = self.v.getSuspendedState()

# KeyManager
self.lastValidateTime = self.deployerContract.tx.timestamp
self.lastValidateTime = 0
self.keyIDToCurKeys = {AGG: AGG_SIGNER_1}
self.allKeys = [*self.keyIDToCurKeys.values()] + (
[Signer.gen_signer(None, {})]
Expand Down Expand Up @@ -2123,7 +2123,7 @@ def rule_upgrade_keyManager(self, st_sender):

self._updateBalancesOnUpgrade(self.km, newKeyManager)
self.km = newKeyManager
self.lastValidateTime = self.km.tx.timestamp
self.lastValidateTime = 0

# Deploys a new Vault and transfers the funds from the old Vault to the new one
def rule_upgrade_Vault(self, st_sender, st_sleep_time):
Expand Down
2 changes: 1 addition & 1 deletion tests/stateful/test_keyManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(cls, a, cfDeploy):

# Reset the local versions of state to compare the contract to after every run
def setup(self):
self.lastValidateTime = self.deployerContract.tx.timestamp
self.lastValidateTime = 0
self.keyIDToCurKeys = {AGG: AGG_SIGNER_1}
self.allKeys = [*self.keyIDToCurKeys.values()] + (
[Signer.gen_signer(None, {})]
Expand Down
4 changes: 2 additions & 2 deletions tests/stateful/test_upgradability.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setup(self):
self.v = self.orig_v
self.km = self.orig_km

self.lastValidateTime = self.deployerContract.tx.timestamp
self.lastValidateTime = 0
self.numTxsTested = 0

# StateChainGateway
Expand Down Expand Up @@ -104,7 +104,7 @@ def rule_upgrade_keyManager(self, st_sender):
assert aggKeyNonceConsumer.getKeyManager() == newKeyManager

self.km = newKeyManager
self.lastValidateTime = self.km.tx.timestamp
self.lastValidateTime = 0

# Deploys a new Vault and transfers the funds from the old Vault to the new one
def rule_upgrade_Vault(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/keyManager/test_keyManager_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
def test_constructor(a, cf):
assert cf.keyManager.getAggregateKey() == AGG_SIGNER_1.getPubDataWith0x()
assert cf.keyManager.getGovernanceKey() == cf.GOVERNOR
assert cf.keyManager.getLastValidateTime() == cf.deployerContract.tx.timestamp
assert cf.keyManager.getLastValidateTime() == 0
9 changes: 3 additions & 6 deletions tests/unit/keyManager/test_setAggKeyWithGovKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@


def test_setAggKeyWithGovKey(cf):
chain.sleep(AGG_KEY_TIMEOUT)
setAggKeyWithGovKey_test(cf)


def test_setAggKeyWithGovKey_rev_time(cf):
with reverts(REV_MSG_DELAY):
cf.keyManager.setAggKeyWithGovKey(
cf.keyManager.getAggregateKey(), {"from": cf.GOVERNOR}
)
def test_setAggKeyWithGovKey_delay_success(cf):
chain.sleep(AGG_KEY_TIMEOUT)
setAggKeyWithGovKey_test(cf)


def test_setAggKeyWithGovKey_rev_governor(cf):
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/vault/test_executeActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ def test_executeActions_revgas(cf, multicall):
# Gas limit that doesn't allow the Multicall to execute the actions but leaves
# enough gas to trigger "Vault: gasMulticall too low". Succesfull tx according
# to gas test is ~140k but it doesn't succeed until gas_limit is not at least
# 180k (without the gas check). Then from 190k to 210k, when adding the gas check,
# it reverts with "Vault: gasMulticall too low". After 210k it will succeed as normal
# 180k (without the gas check). Then from 190k to 220k, when adding the gas check,
# it reverts with "Vault: gasMulticall too low". After 220k it will succeed as normal
gas_limit = 200000

# Reverted with empty revert string is to catch the invalid opcode
Expand All @@ -437,7 +437,7 @@ def test_executeActions_revgas(cf, multicall):
{"from": cf.DENICE, "gas_limit": gas_limit},
)

gas_limit = 210000
gas_limit = 220000

tx = cf.vault.executeActions(
sigData,
Expand All @@ -448,7 +448,7 @@ def test_executeActions_revgas(cf, multicall):


@given(
st_gas_limit=strategy("uint256", min_value=80000, max_value=250000),
st_gas_limit=strategy("uint256", min_value=100000, max_value=250000),
)
def test_executeActions_gas(cf, multicall, st_gas_limit):
print("gas limit", st_gas_limit)
Expand All @@ -473,7 +473,7 @@ def test_executeActions_gas(cf, multicall, st_gas_limit):

# Exact gas limit that makes the transaction have enough gas to pass the
# gas check, execute the actions and succeeed.
cutoff_gas_limit = 202288
cutoff_gas_limit = 219452

# On low gas_limit values it will revert with not enough gas error and other
# error such as no reason string. Arbitrary 80k under the cutoff gas limit
Expand Down

0 comments on commit faaedad

Please sign in to comment.