Skip to content

Commit

Permalink
test: add tests for new behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ste committed Sep 27, 2023
1 parent e20da4d commit 18fa7f9
Showing 1 changed file with 96 additions and 15 deletions.
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 18fa7f9

Please sign in to comment.