Skip to content

Commit

Permalink
Merge pull request #724 from lukso-network/DEV-7978
Browse files Browse the repository at this point in the history
feat: allow `endingTimestamp` to be 0
  • Loading branch information
CJ42 authored Sep 27, 2023
2 parents e6fb55d + d6ef07b commit ff83dfb
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 15 deletions.
4 changes: 4 additions & 0 deletions contracts/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ abstract contract LSP25MultiChannelNonce {
revert RelayCallBeforeStartTime();
}

// Allow `endingTimestamp` to be 0
// Allow execution anytime past `startingTimestamp`
if (endingTimestamp == 0) return;

// solhint-disable-next-line not-rely-on-time
if (block.timestamp > endingTimestamp) {
revert RelayCallExpired();
Expand Down
111 changes: 96 additions & 15 deletions tests/LSP6KeyManager/Relay/ExecuteRelayCall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,11 +727,12 @@ export const shouldBehaveLikeExecuteRelayCall = (
startingTimestamp,
endingTimestamp,
);
const randomNumber = 12345;
const calldata = context.universalProfile.interface.encodeFunctionData('execute', [
0,
OPERATION_TYPES.CALL,
targetContract.address,
0,
targetContract.interface.encodeFunctionData('setNumber', [nonce]),
targetContract.interface.encodeFunctionData('setNumber', [randomNumber]),
]);
const value = 0;
const signature = await signLSP6ExecuteRelayCall(
Expand All @@ -747,7 +748,7 @@ export const shouldBehaveLikeExecuteRelayCall = (
.connect(relayer)
.executeRelayCall(signature, nonce, validityTimestamps, calldata);

expect(await targetContract.getNumber()).to.equal(nonce);
expect(await targetContract.getNumber()).to.equal(randomNumber);
});
});

Expand Down Expand Up @@ -825,11 +826,12 @@ export const shouldBehaveLikeExecuteRelayCall = (
startingTimestamp,
endingTimestamp,
);
const randomNumber = 12345;
const calldata = context.universalProfile.interface.encodeFunctionData('execute', [
0,
OPERATION_TYPES.CALL,
targetContract.address,
0,
targetContract.interface.encodeFunctionData('setNumber', [nonce]),
targetContract.interface.encodeFunctionData('setNumber', [randomNumber]),
]);
const value = 0;
const signature = await signLSP6ExecuteRelayCall(
Expand All @@ -845,7 +847,7 @@ export const shouldBehaveLikeExecuteRelayCall = (
.connect(relayer)
.executeRelayCall(signature, nonce, validityTimestamps, calldata);

expect(await targetContract.getNumber()).to.equal(nonce);
expect(await targetContract.getNumber()).to.equal(randomNumber);
});
});

Expand All @@ -862,11 +864,12 @@ export const shouldBehaveLikeExecuteRelayCall = (
startingTimestamp,
endingTimestamp,
);
const randomNumber = 12345;
const calldata = context.universalProfile.interface.encodeFunctionData('execute', [
0,
OPERATION_TYPES.CALL,
targetContract.address,
0,
targetContract.interface.encodeFunctionData('setNumber', [nonce]),
targetContract.interface.encodeFunctionData('setNumber', [randomNumber]),
]);
const value = 0;
const signature = await signLSP6ExecuteRelayCall(
Expand All @@ -884,7 +887,7 @@ export const shouldBehaveLikeExecuteRelayCall = (
.connect(relayer)
.executeRelayCall(signature, nonce, validityTimestamps, calldata);

expect(await targetContract.getNumber()).to.equal(nonce);
expect(await targetContract.getNumber()).to.equal(randomNumber);
});
});
});
Expand Down Expand Up @@ -964,11 +967,12 @@ export const shouldBehaveLikeExecuteRelayCall = (
startingTimestamp,
endingTimestamp,
);
const randomNumber = 12345;
const calldata = context.universalProfile.interface.encodeFunctionData('execute', [
0,
OPERATION_TYPES.CALL,
targetContract.address,
0,
targetContract.interface.encodeFunctionData('setNumber', [nonce]),
targetContract.interface.encodeFunctionData('setNumber', [randomNumber]),
]);
const value = 0;
const signature = await signLSP6ExecuteRelayCall(
Expand All @@ -986,7 +990,7 @@ export const shouldBehaveLikeExecuteRelayCall = (
.connect(relayer)
.executeRelayCall(signature, nonce, validityTimestamps, calldata);

expect(await targetContract.getNumber()).to.equal(nonce);
expect(await targetContract.getNumber()).to.equal(randomNumber);
});
});
});
Expand All @@ -995,11 +999,12 @@ export const shouldBehaveLikeExecuteRelayCall = (
it('passes', async () => {
const nonce = await context.keyManager.callStatic.getNonce(signer.address, 14);
const validityTimestamps = 0;
const randomNumber = 12345;
const calldata = context.universalProfile.interface.encodeFunctionData('execute', [
0,
OPERATION_TYPES.CALL,
targetContract.address,
0,
targetContract.interface.encodeFunctionData('setNumber', [nonce]),
targetContract.interface.encodeFunctionData('setNumber', [randomNumber]),
]);
const value = 0;
const signature = await signLSP6ExecuteRelayCall(
Expand All @@ -1015,7 +1020,83 @@ export const shouldBehaveLikeExecuteRelayCall = (
.connect(relayer)
.executeRelayCall(signature, nonce, validityTimestamps, calldata);

expect(await targetContract.getNumber()).to.equal(nonce);
expect(await targetContract.getNumber()).to.equal(randomNumber);
});
});

describe('when `endingTimestamp == 0`', () => {
describe('`startingTimestamp` < now', () => {
it('passes', async () => {
const now = await time.latest();

const startingTimestamp = now - 100;
const endingTimestamp = 0;

const nonce = await context.keyManager.callStatic.getNonce(signer.address, 14);
const validityTimestamps = createValidityTimestamps(
startingTimestamp,
endingTimestamp,
);
const randomNumber = 12345;
const calldata = context.universalProfile.interface.encodeFunctionData('execute', [
OPERATION_TYPES.CALL,
targetContract.address,
0,
targetContract.interface.encodeFunctionData('setNumber', [randomNumber]),
]);
const value = 0;
const signature = await signLSP6ExecuteRelayCall(
context.keyManager,
nonce.toString(),
validityTimestamps,
signerPrivateKey,
value,
calldata,
);

await context.keyManager
.connect(relayer)
.executeRelayCall(signature, nonce, validityTimestamps, calldata);

expect(await targetContract.getNumber()).to.equal(randomNumber);
});
});

describe('`startingTimestamp` > now', () => {
it('reverts', async () => {
const now = await time.latest();

const startingTimestamp = now + 100;
const endingTimestamp = 0;

const nonce = await context.keyManager.callStatic.getNonce(signer.address, 14);
const validityTimestamps = createValidityTimestamps(
startingTimestamp,
endingTimestamp,
);
const randomNumber = 12345;
const calldata = context.universalProfile.interface.encodeFunctionData('execute', [
OPERATION_TYPES.CALL,
targetContract.address,
0,
targetContract.interface.encodeFunctionData('setNumber', [randomNumber]),
]);
const value = 0;
const signature = await signLSP6ExecuteRelayCall(
context.keyManager,
nonce.toString(),
validityTimestamps,
signerPrivateKey,
value,
calldata,
);

await expect(
context.keyManager
.connect(relayer)
.executeRelayCall(signature, nonce, validityTimestamps, calldata),
).to.be.revertedWithCustomError(context.keyManager, 'RelayCallBeforeStartTime');
});
});
});
});
Expand Down

0 comments on commit ff83dfb

Please sign in to comment.