Skip to content

Commit

Permalink
test: add tests for LSP25
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Aug 18, 2023
1 parent b581c8b commit a31adc6
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@ benchmark.md
/userdocs

# test temporary folder
/.test
/.test
contracts-exposed/
14 changes: 10 additions & 4 deletions contracts/LSP25ExecuteRelayCall/LSP25Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
pragma solidity ^0.8.4;

/**
* @notice The relay call failed because an invalid nonce was provided for the address `signer` that signed the execute relay call.
* Invalid nonce: `invalidNonce`, signature of signer: `signature`.
*
* @dev Reverts when the `signer` address retrieved from the `signature` has an invalid nonce: `invalidNonce`.
*
* @param signer The address of the signer
* @param invalidNonce The nonce retrieved for the `signer` address
* @param signature The signature used to retrieve the `signer` address
* @param signer The address of the signer.
* @param invalidNonce The nonce retrieved for the `signer` address.
* @param signature The signature used to retrieve the `signer` address.
*/
error InvalidRelayNonce(address signer, uint256 invalidNonce, bytes signature);

/**
* @dev Reverts when the start timestamp provided to {executeRelayCall} function is bigger than the current timestamp.
* @notice Relay call not valid yet.
*
* @dev Reverts when the relay call is cannot yet bet executed.
* This mean that the starting timestamp provided to {executeRelayCall} function is bigger than the current timestamp.
*/
error RelayCallBeforeStartTime();

Expand Down
26 changes: 0 additions & 26 deletions contracts/LSP6KeyManager/LSP6Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ error NotRecognisedPermissionKey(bytes32 dataKey);
*/
error InvalidLSP6Target();

/**
* @notice The relay call failed because an invalid nonce was provided for the address `signer` that signed the execute relay call.
* Invalid nonce: `invalidNonce`, signature of signer: `signature`.
*
* @dev Reverts when the `signer` address retrieved from the `signature` has an invalid nonce: `invalidNonce`.
*
* @param signer The address of the signer
* @param invalidNonce The nonce retrieved for the `signer` address
* @param signature The signature used to retrieve the `signer` address
*/
error InvalidRelayNonce(address signer, uint256 invalidNonce, bytes signature);

/**
* @notice The Key Manager could not verify the calldata of the transaction because it could not recognise
* the function being called. Invalid function selector: `invalidFunction`.
Expand Down Expand Up @@ -227,20 +215,6 @@ error CannotSendValueToSetData();
*/
error CallingKeyManagerNotAllowed();

/**
* @notice Relay call not valid yet.
*
* @dev Reverts when the start timestamp provided to {executeRelayCall} function is bigger than the current timestamp.
*/
error RelayCallBeforeStartTime();

/**
* @notice The date of the relay call expired.
*
* @dev Reverts when the period to execute the relay call has expired.
*/
error RelayCallExpired();

/**
* @dev reverts when the address of the Key Manager is being set as extensions for lsp20 functions
*/
Expand Down
4 changes: 4 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import '@nomiclabs/hardhat-web3';
import '@b00ste/hardhat-dodoc';
import { dodocConfig } from './dodoc/config';

// Expose the internal functions of the contracts for testing.
// This avoids creating too many mock contracts for exposing the internal functions.
import 'hardhat-exposed';

dotenvConfig({ path: resolve(__dirname, './.env') });

function getTestnetChainConfig(): NetworkUserConfig {
Expand Down
139 changes: 139 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"test:lsp20": "hardhat test --no-compile tests/LSP20CallVerification/LSP6/LSP20WithLSP6.test.ts",
"test:lsp20init": "hardhat test --no-compile tests/LSP20CallVerification/LSP6/LSP20WithLSP6Init.test.ts",
"test:lsp23": "hardhat test --no-compile tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts",
"test:lsp25": "hardhat test --no-compile tests/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.test.ts",
"test:universalfactory": "hardhat test --no-compile tests/LSP16UniversalFactory/LSP16UniversalFactory.test.ts",
"test:reentrancy": "hardhat test --no-compile tests/Reentrancy/Reentrancy.test.ts",
"test:reentrancyinit": "hardhat test --no-compile tests/Reentrancy/ReentrancyInit.test.ts",
Expand Down Expand Up @@ -127,6 +128,7 @@
"hardhat-contract-sizer": "^2.8.0",
"hardhat-deploy": "^0.11.25",
"hardhat-deploy-ethers": "^0.3.0-beta.13",
"hardhat-exposed": "^0.3.11",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-packager": "^1.4.2",
"keccak256": "1.0.6",
Expand Down
19 changes: 19 additions & 0 deletions tests/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ethers } from 'hardhat';
import { expect } from 'chai';

Check warning on line 2 in tests/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.test.ts

View workflow job for this annotation

GitHub Actions / build

'expect' is defined but never used

describe('LSP25MultiChannelNonce', () => {
let contract;
let account;

before(async () => {
account = (await ethers.getSigners())[0];

const LSP25Factory = await ethers.getContractFactory('$LSP25MultiChannelNonce');
contract = await LSP25Factory.deploy();
});

it('test', async () => {
const result = await contract.$_isValidNonce(account.address, 0);
console.log(result);
});
});

0 comments on commit a31adc6

Please sign in to comment.