Skip to content

Commit

Permalink
feat: Testing kit (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv authored Sep 16, 2024
1 parent d91ac8f commit 0d03508
Show file tree
Hide file tree
Showing 133 changed files with 935 additions and 1,479 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/api-kit-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ jobs:
- name: Build
run: yarn build

- name: Make testing-kit.js executable
run: chmod +x packages/testing-kit/dist/bin/testing-kit.js

- name: Add script directory to PATH
run: echo "$(pwd)/packages/testing-kit/dist/bin" >> $GITHUB_PATH

- name: Test
run: |
cd packages/api-kit
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/protocol-kit-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ jobs:
- run: |
yarn install --frozen-lockfile
yarn build
- name: Make testing-kit.js executable
run: chmod +x packages/testing-kit/dist/bin/testing-kit.js
- name: Add script directory to PATH
run: echo "$(pwd)/packages/testing-kit/dist/bin" >> $GITHUB_PATH
- name: Test ${{ matrix.provider }} - Safe ${{ matrix.contract-version }}
run: |
cd packages/protocol-kit
ls -la $(pwd)/node_modules/.bin
yarn test:hardhat:${{ matrix.provider }}:${{ matrix.contract-version }}
6 changes: 6 additions & 0 deletions .github/workflows/sdk-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
- name: Build
run: yarn build

- name: Make testing-kit.js executable
run: chmod +x packages/testing-kit/dist/bin/testing-kit.js

- name: Add script directory to PATH
run: echo "$(pwd)/packages/testing-kit/dist/bin" >> $GITHUB_PATH

- name: Test
env:
PRIVATE_KEY: ${{ secrets.TESTING_PRIVATE_KEY }}
Expand Down
2 changes: 0 additions & 2 deletions packages/api-kit/.env.example

This file was deleted.

52 changes: 0 additions & 52 deletions packages/api-kit/hardhat.config.ts

This file was deleted.

18 changes: 8 additions & 10 deletions packages/api-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"API"
],
"scripts": {
"test:web3": "export TESTS_PATH=tests/endpoint && export ETH_LIB=web3 && nyc --reporter=lcov hardhat test",
"test:ethers": "export TESTS_PATH=tests/endpoint && export ETH_LIB=ethers && nyc --reporter=lcov hardhat test",
"test:viem": "export TESTS_PATH=tests/endpoint && export ETH_LIB=viem && nyc --reporter=lcov hardhat test",
"test:web3": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=web3 && nyc --reporter=lcov testing-kit.js test 'tests/endpoint/*.test.*'",
"test:ethers": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=ethers && nyc --reporter=lcov testing-kit.js test 'tests/endpoint/*.test.*'",
"test:viem": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=viem && nyc --reporter=lcov testing-kit.js test 'tests/endpoint/*.test.*'",
"test": "yarn test:viem",
"test:ci:web3": "export TESTS_PATH=tests/e2e && export ETH_LIB=web3 && nyc --reporter=lcov hardhat test",
"test:ci:ethers": "export TESTS_PATH=tests/e2e && export ETH_LIB=ethers && nyc --reporter=lcov hardhat test",
"test:ci:viem": "export TESTS_PATH=tests/e2e && export ETH_LIB=viem && nyc --reporter=lcov hardhat test",
"test:ci:web3": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=web3 && nyc --reporter=lcov testing-kit.js test 'tests/e2e/*.test.*'",
"test:ci:ethers": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=ethers && nyc --reporter=lcov testing-kit.js test 'tests/e2e/*.test.*'",
"test:ci:viem": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=viem && nyc --reporter=lcov testing-kit.js test 'tests/e2e/*.test.*'",
"test:ci": "yarn test:ci:viem",
"format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"",
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
Expand All @@ -41,24 +41,22 @@
"devDependencies": {
"@nomicfoundation/hardhat-viem": "^2.0.2",
"@safe-global/relay-kit": "^3.1.0",
"@safe-global/testing-kit": "^0.0.1-alpha.0",
"@types/chai": "^4.3.16",
"@types/chai-as-promised": "^7.1.8",
"@types/mocha": "^10.0.6",
"@types/node-fetch": "^2.6.11",
"@types/sinon-chai": "^3.2.11",
"@types/yargs": "^17.0.32",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"ethers": "^6.13.1",
"hardhat": "2.20.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"semver": "^7.6.1",
"sinon": "^14.0.2",
"sinon-chai": "^3.7.0",
"tsconfig-paths": "^4.2.0",
"web3": "^4.7.0",
"yargs": "^17.7.2"
"web3": "^4.7.0"
},
"dependencies": {
"@safe-global/protocol-kit": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-kit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"composite": true,
"outDir": "dist"
},
"include": ["src/**/*", "tests/**/*", "hardhat.config.ts"]
"include": ["src/**/*", "tests/**/*"]
}
43 changes: 18 additions & 25 deletions packages/protocol-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
"update-safe-deployments": "ts-node scripts/safe-deployments/updateLocalNetworks.ts",
"check-short-name-integrity": "ts-node scripts/safe-deployments/checkShortNameIntegrity.ts",
"test": "mocha -r ts-node/register -r tsconfig-paths/register tests/unit/**/*.ts",
"test:hardhat:web3:v1.0.0": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.0.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:web3:v1.1.1": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.1.1 && hardhat deploy && nyc hardhat test",
"test:hardhat:web3:v1.2.0": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.2.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:web3:v1.3.0": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.3.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:web3:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.4.1 && hardhat deploy && nyc hardhat test",
"test:hardhat:ethers:v1.0.0": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.0.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:ethers:v1.1.1": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.1.1 && hardhat deploy && nyc hardhat test",
"test:hardhat:ethers:v1.2.0": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.2.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:ethers:v1.3.0": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.3.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:ethers:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.4.1 && hardhat deploy && nyc hardhat test",
"test:hardhat:viem:v1.0.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.0.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:viem:v1.1.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.1.1 && hardhat deploy && nyc hardhat test",
"test:hardhat:viem:v1.2.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.2.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:viem:v1.3.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.3.0 && hardhat deploy && nyc hardhat test",
"test:hardhat:viem:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.4.1 && hardhat deploy && nyc hardhat test",
"test:hardhat:web3:v1.0.0": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.0.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:web3:v1.1.1": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.1.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:web3:v1.2.0": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.2.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:web3:v1.3.0": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.3.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:web3:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=web3 && export SAFE_VERSION=1.4.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:ethers:v1.0.0": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.0.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:ethers:v1.1.1": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.1.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:ethers:v1.2.0": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.2.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:ethers:v1.3.0": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.3.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:ethers:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=ethers && export SAFE_VERSION=1.4.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:viem:v1.0.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.0.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:viem:v1.1.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.1.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:viem:v1.2.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.2.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:viem:v1.3.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.3.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:viem:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.4.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"coverage": "nyc report --reporter=lcov",
"format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"",
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
"unbuild": "rimraf dist artifacts deployments cache .nyc_output *.tsbuildinfo",
"build": "yarn unbuild && hardhat compile && yarn check-safe-deployments && NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
"build": "yarn unbuild && yarn check-safe-deployments && NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
},
"repository": {
"type": "git",
Expand All @@ -51,27 +51,20 @@
],
"homepage": "https://github.com/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@gnosis.pm/safe-contracts-v1.3.0": "npm:@gnosis.pm/safe-contracts@1.3.0",
"@nomicfoundation/hardhat-viem": "^2.0.2",
"@openzeppelin/contracts": "^2.5.1",
"@safe-global/safe-contracts-v1.4.1": "npm:@safe-global/safe-contracts@1.4.1",
"@safe-global/safe-passkey": "0.2.0-alpha.1",
"@safe-global/testing-kit": "^0.0.1-alpha.0",
"@types/chai": "^4.3.16",
"@types/chai-as-promised": "^7.1.8",
"@types/mocha": "^10.0.6",
"@types/semver": "^7.5.8",
"@types/yargs": "^17.0.32",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"dotenv": "^16.4.5",
"ethers": "^6.13.1",
"hardhat": "^2.19.3",
"hardhat-deploy": "^0.11.45",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"tsconfig-paths": "^4.2.0",
"web3": "^4.7.0",
"yargs": "^17.7.2"
"web3": "^4.7.0"
},
"dependencies": {
"@noble/hashes": "^1.3.3",
Expand Down
1 change: 0 additions & 1 deletion packages/protocol-kit/src/contracts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export function encodeCreateProxyWithNonce(
initializer: string,
salt?: string
) {
console.log(`safeSingletonAddress`, safeSingletonAddress)
return safeProxyFactoryContract.encode('createProxyWithNonce', [
safeSingletonAddress,
asHex(initializer),
Expand Down
52 changes: 21 additions & 31 deletions packages/protocol-kit/tests/e2e/contractManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
import { safeVersionDeployed } from '@safe-global/protocol-kit/hardhat/deploy/deploy-contracts'
import Safe, { ContractNetworksConfig, PredictedSafeProps } from '@safe-global/protocol-kit/index'
import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { deployments } from 'hardhat'
import { getContractNetworks } from './utils/setupContractNetworks'
import {
safeVersionDeployed,
setupTests,
getCompatibilityFallbackHandler,
getCreateCall,
getFactory,
getMultiSend,
getMultiSendCallOnly,
getSafeSingleton,
getSafeWithOwners,
getSignMessageLib,
getSimulateTxAccessor
} from './utils/setupContracts'
getSimulateTxAccessor,
getSafeWebAuthnSharedSigner,
getSafeWebAuthnSignerFactory
} from '@safe-global/testing-kit'
import Safe, { ContractNetworksConfig, PredictedSafeProps } from '@safe-global/protocol-kit/index'
import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { getEip1193Provider } from './utils/setupProvider'
import { getAccounts } from './utils/setupTestNetwork'

chai.use(chaiAsPromised)

describe('Safe contracts manager', () => {
const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => {
await deployments.fixture()
const accounts = await getAccounts()
const chainId = BigInt(await getChainId())
const contractNetworks = await getContractNetworks(chainId)
const provider = getEip1193Provider()
return {
safe: await getSafeWithOwners([accounts[0].address]),
accounts,
contractNetworks,
chainId,
provider
}
})
const provider = getEip1193Provider()

describe('create', async () => {
it('should initialize the SDK with a Safe that is not deployed', async () => {
const { accounts, contractNetworks, provider } = await setupTests()
const { accounts, contractNetworks } = await setupTests()
const predictedSafe: PredictedSafeProps = {
safeAccountConfig: {
owners: [accounts[0].address],
Expand All @@ -59,7 +45,7 @@ describe('Safe contracts manager', () => {
})

it('should fail if the current network is not a default network and no contractNetworks is provided', async () => {
const { safe, provider } = await setupTests()
const { safe } = await setupTests()
const safeAddress = safe.address
await chai
.expect(
Expand All @@ -72,7 +58,7 @@ describe('Safe contracts manager', () => {
})

it('should fail if SafeProxy contract is not deployed on the current network', async () => {
const { contractNetworks, provider } = await setupTests()
const { contractNetworks } = await setupTests()
await chai
.expect(
Safe.init({
Expand All @@ -85,7 +71,7 @@ describe('Safe contracts manager', () => {
})

it('should fail if MultiSend contract is specified in contractNetworks but not deployed', async () => {
const { safe, chainId, provider } = await setupTests()
const { safe, chainId } = await setupTests()
const customContractNetworks: ContractNetworksConfig = {
[chainId.toString()]: {
safeSingletonAddress: ZERO_ADDRESS,
Expand All @@ -103,7 +89,11 @@ describe('Safe contracts manager', () => {
createCallAddress: ZERO_ADDRESS,
createCallAbi: (await getCreateCall()).abi,
simulateTxAccessorAddress: ZERO_ADDRESS,
simulateTxAccessorAbi: (await getSimulateTxAccessor()).abi
simulateTxAccessorAbi: (await getSimulateTxAccessor()).abi,
safeWebAuthnSignerFactoryAddress: ZERO_ADDRESS,
safeWebAuthnSignerFactoryAbi: (await getSafeWebAuthnSignerFactory()).abi,
safeWebAuthnSharedSignerAddress: ZERO_ADDRESS,
safeWebAuthnSharedSignerAbi: (await getSafeWebAuthnSharedSigner()).abi
}
}

Expand All @@ -120,7 +110,7 @@ describe('Safe contracts manager', () => {
})

it('should set the MultiSend contract available on the current network', async () => {
const { safe, chainId, contractNetworks, provider } = await setupTests()
const { safe, chainId, contractNetworks } = await setupTests()
const safeAddress = safe.address
const safeSdk = await Safe.init({
provider,
Expand Down
Loading

0 comments on commit 0d03508

Please sign in to comment.