Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Testing kit #962

Merged
merged 56 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4d3825f
initial commit testing kit
yagopv Aug 27, 2024
cf7aece
Add passkeys files
yagopv Aug 27, 2024
b3f756f
add testing-kit as dep
yagopv Aug 27, 2024
803bbc4
Add test script to testing kit
yagopv Aug 27, 2024
9156ecc
Remove assets from protocol-kit
yagopv Aug 27, 2024
e21b240
Remove yargs
yagopv Aug 27, 2024
9256e1f
Include deploy compile
yagopv Aug 27, 2024
efa6e6d
Add .bin to the PATH
yagopv Aug 27, 2024
48b2ffd
Add .bin to the path
yagopv Aug 27, 2024
6726060
Add .bin to path
yagopv Aug 27, 2024
3bc136d
Debug testing-kit
yagopv Aug 27, 2024
f2df79e
Print current dir
yagopv Aug 27, 2024
82b6aba
Try to add to the path
yagopv Aug 27, 2024
5673940
Add reference as file:
yagopv Aug 27, 2024
7764f54
Move to the root
yagopv Aug 27, 2024
38922c1
debug
yagopv Aug 27, 2024
bd411a4
Add yarnrc
yagopv Aug 27, 2024
0c3ef9f
Remove frozen lockfile
yagopv Aug 27, 2024
3b34257
Some changes
yagopv Aug 27, 2024
45c00f4
Remove node_modules
yagopv Aug 27, 2024
274fe7d
Add testing kit to the root
yagopv Aug 27, 2024
563473b
more tezsting
yagopv Aug 27, 2024
b8817bc
try --force
yagopv Aug 27, 2024
f66309b
REmove echoes
yagopv Aug 27, 2024
3f08cc5
Remove --force
yagopv Aug 27, 2024
4b38bb8
Try to ad manually to path
yagopv Aug 27, 2024
e309e49
concrete file
yagopv Aug 27, 2024
d3d33b6
Try with the script
yagopv Aug 27, 2024
a30ae86
fix
yagopv Aug 27, 2024
610a084
Remove hardhat
yagopv Aug 28, 2024
b2ee1bb
Update api-kit to use testing-kit
yagopv Aug 28, 2024
5d66347
Add hardhat as peer for testing-kit
yagopv Aug 28, 2024
841b21c
Remove @ts-expect-error
yagopv Aug 28, 2024
e1ce2c1
Move files around
yagopv Aug 29, 2024
2927072
Revert "Move files around"
yagopv Aug 29, 2024
3104abb
Recvert some changes
yagopv Aug 29, 2024
ef9a7f2
Update tests in protocol-kit and remove duplicates
yagopv Aug 29, 2024
cb31d7a
fix
yagopv Aug 29, 2024
20f7e1e
Trigger CI
yagopv Sep 12, 2024
5f5bbce
.env file no longer needed in api-kit
yagopv Sep 12, 2024
0b03f2f
yargs no longer necessary
yagopv Sep 12, 2024
9f93937
Update package.json
yagopv Sep 13, 2024
7bf8f0d
chore: remove unnecessary await
dasanra Sep 13, 2024
0fd6ee0
chore: remove unused function
dasanra Sep 13, 2024
f4526cc
chore: cleanup unnecessary code
dasanra Sep 13, 2024
3fb35d6
remove unnecessary script
yagopv Sep 16, 2024
2e71f3b
improve test typing
yagopv Sep 16, 2024
1b5cb62
chore: remove unused dependency
dasanra Sep 16, 2024
f8ef728
chore: set alpha release
dasanra Sep 16, 2024
0afa358
Use .bin testing-kit
yagopv Sep 16, 2024
c25c985
Test
yagopv Sep 16, 2024
1352603
Test
yagopv Sep 16, 2024
b0a1b7c
Revert testing-kit bin tests
yagopv Sep 16, 2024
1ac4b98
Merge branch 'development' of https://github.com/safe-global/safe-cor…
yagopv Sep 16, 2024
d6fb7f1
yarn lock
yagopv Sep 16, 2024
902149f
trigger ci
yagopv Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading