Skip to content

Commit

Permalink
Merge branch 'develop' into DEV-3725
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Sep 27, 2023
2 parents b6b2211 + ff83dfb commit 5a48357
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 29 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
Original file line number Diff line number Diff line change
Expand Up @@ -1381,11 +1381,11 @@ Emitted when the allowance of a `spender` for an `owner` is set by a call to [`a

#### Parameters

| Name | Type | Description |
| ------------------------ | :-------: | ------------------------------------------ |
| `owner` **`indexed`** | `address` | The address of the owner of the `tokenId`. |
| `operator` **`indexed`** | `address` | The address set as operator. |
| `tokenId` **`indexed`** | `uint256` | The approved tokenId. |
| Name | Type | Description |
| ------------------------ | :-------: | ---------------------------- |
| `owner` **`indexed`** | `address` | The account giving approval |
| `operator` **`indexed`** | `address` | The address set as operator. |
| `tokenId` **`indexed`** | `uint256` | The approved tokenId. |

<br/>

Expand Down Expand Up @@ -1549,8 +1549,8 @@ Emitted when `value` tokens are moved from one account (`from`) to another (`to`

| Name | Type | Description |
| ----------------------- | :-------: | ------------------------ |
| `from` **`indexed`** | `address` | The sending address. |
| `to` **`indexed`** | `address` | The receiving address. |
| `from` **`indexed`** | `address` | The sending address |
| `to` **`indexed`** | `address` | The receiving address |
| `tokenId` **`indexed`** | `uint256` | The tokenId to transfer. |

<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,11 +1423,11 @@ Emitted when the allowance of a `spender` for an `owner` is set by a call to [`a

#### Parameters

| Name | Type | Description |
| ------------------------ | :-------: | ------------------------------------------ |
| `owner` **`indexed`** | `address` | The address of the owner of the `tokenId`. |
| `operator` **`indexed`** | `address` | The address set as operator. |
| `tokenId` **`indexed`** | `uint256` | The approved tokenId. |
| Name | Type | Description |
| ------------------------ | :-------: | ---------------------------- |
| `owner` **`indexed`** | `address` | The account giving approval |
| `operator` **`indexed`** | `address` | The address set as operator. |
| `tokenId` **`indexed`** | `uint256` | The approved tokenId. |

<br/>

Expand Down Expand Up @@ -1591,8 +1591,8 @@ Emitted when `value` tokens are moved from one account (`from`) to another (`to`

| Name | Type | Description |
| ----------------------- | :-------: | ------------------------ |
| `from` **`indexed`** | `address` | The sending address. |
| `to` **`indexed`** | `address` | The receiving address. |
| `from` **`indexed`** | `address` | The sending address |
| `to` **`indexed`** | `address` | The receiving address |
| `tokenId` **`indexed`** | `uint256` | The tokenId to transfer. |

<br/>
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 5a48357

Please sign in to comment.