Skip to content

Commit

Permalink
Refactor Safe interface to ISafeTest for test usage. (#491)
Browse files Browse the repository at this point in the history
* Add GitHub Actions workflow for safe-modules-allowance
* Update package.json scripts for linting and formatting
* Update import statements in test helpers to use ISafeTest

This PR was needed to fix the allowance module tests broken by the
interface name collision introduced in
#489, also with the
GitHub action we're less likely to break the tests again
  • Loading branch information
mmv08 authored Aug 30, 2024
1 parent e418cd8 commit bc76ffd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci_allowance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: safe-modules-allowance
on:
push:
paths:
- 'modules/allowances/**'

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: pnpm
- run: |
pnpm install
pnpm run --filter "@safe-global/safe-allowance-module" coverage
- uses: coverallsapp/github-action@master
with:
path-to-lcov: modules/allowances/coverage/lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: pnpm
- run: |
pnpm install
pnpm run --filter "@safe-global/safe-allowance-module" lint
pnpm run --filter "@safe-global/safe-allowance-module" fmt:check
pnpm run --filter "@safe-global/safe-allowance-module" build
2 changes: 1 addition & 1 deletion modules/allowances/contracts/test/ISafe.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0 <0.9.0;

interface ISafe {
interface ISafeTest {
function getThreshold() external view returns (uint256);

function getChainId() external view returns (uint256);
Expand Down
13 changes: 9 additions & 4 deletions modules/allowances/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
"prepare": "pnpm run clean && npm run build",
"lint": "pnpm run lint:sol && npm run lint:ts",
"lint:sol": "solhint 'contracts/**/*.sol'",
"lint:ts": "eslint 'tasks/**/*.ts' 'test/**/*.ts' --max-warnings 0 --fix",
"fmt": "pnpm run fmt:sol && npm run fmt:ts",
"fmt:sol": "prettier 'contracts/**/*.sol' -w",
"fmt:ts": "prettier 'tasks/**/*.ts' 'test/**/*.ts' -w"
"lint:sol:fix": "solhint 'contracts/**/*.sol' --fix",
"lint:ts": "eslint 'tasks/**/*.ts' 'test/**/*.ts' --max-warnings 0",
"lint:ts:fix": "eslint 'tasks/**/*.ts' 'test/**/*.ts' --max-warnings 0 --fix",
"fmt": "pnpm run fmt:sol:write && npm run fmt:ts:write",
"fmt:check": "pnpm run fmt:sol:check && npm run fmt:ts:check",
"fmt:sol:check": "prettier 'contracts/**/*.sol' --check",
"fmt:ts:check": "prettier 'tasks/**/*.ts' 'test/**/*.ts' --check",
"fmt:sol:write": "prettier 'contracts/**/*.sol' --write",
"fmt:ts:write": "prettier 'tasks/**/*.ts' 'test/**/*.ts' --write"
},
"author": "[email protected]",
"license": "ISC",
Expand Down
4 changes: 2 additions & 2 deletions modules/allowances/test/test-helpers/execSafeTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
import { TransactionRequest, ZeroAddress } from 'ethers'

import { ISafe } from '../../typechain-types'
import { ISafeTest } from '../../typechain-types'

export default async function execSafeTransaction(safe: ISafe, { to, data, value = 0 }: TransactionRequest, signer: SignerWithAddress) {
export default async function execSafeTransaction(safe: ISafeTest, { to, data, value = 0 }: TransactionRequest, signer: SignerWithAddress) {
const address = await safe.getAddress()
const chainId = await safe.getChainId()
const nonce = await safe.nonce()
Expand Down
4 changes: 2 additions & 2 deletions modules/allowances/test/test-helpers/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
import hre from 'hardhat'

import { AllowanceModule__factory, ISafe__factory, TestToken, TestToken__factory } from '../../typechain-types'
import { AllowanceModule__factory, ISafeTest__factory, TestToken, TestToken__factory } from '../../typechain-types'

import deploySafeProxy from './deploySafeProxy'
import deploySingletons from './deploySingletons'
Expand All @@ -18,7 +18,7 @@ export default async function setup() {
// both the safe and the allowance work by signature
// connect the contracts to a signer that has funds
// but isn't safe owner, or allowance spender
const safe = ISafe__factory.connect(safeAddress, relayer)
const safe = ISafeTest__factory.connect(safeAddress, relayer)
const allowanceModule = AllowanceModule__factory.connect(allowanceModuleAddress, relayer)

// fund the safe
Expand Down

0 comments on commit bc76ffd

Please sign in to comment.