Skip to content

Commit 7c77b81

Browse files
authored
Add the owned safes endpoint; add e2e tests; parse error message (#15)
* Add the owned safes endpoint; add e2e tests; parse error message * Run prettier * Replace reviewdog * Update the error handling and tests * Bump version
1 parent ab53b5b commit 7c77b81

18 files changed

+197
-61
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ jobs:
66
runs-on: ubuntu-latest
77
steps:
88
- uses: actions/checkout@v2
9-
- uses: reviewdog/action-eslint@master
9+
- uses: gnosis/safe-react-eslint-plus-action@main

.github/workflows/test.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ jobs:
77
steps:
88
- uses: actions/checkout@v2
99
- run: npm install
10-
- run: npm test
11-
- uses: mattallty/jest-github-action@master
10+
11+
- name: Run tests
12+
uses: mattallty/jest-github-action@v1
1213
env:
1314
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14-
CI: true
1515
with:
16-
test-command: 'echo done'
16+
test-command: 'npm run test:ci -- --outputFile=/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/jest.results.json'
17+
coverage-comment: false

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"trailingComma": "all",
55
"singleQuote": true,
66
"semi": false
7-
}
7+
}

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ This will create a folder called `openapi` with an OpenAPI JSON and the correspo
1414

1515
## Adding an endpoint
1616

17-
Endpoints are defined in `src/types/gateway.ts` and `src/index.ts. Each endpoint consists of:
17+
Endpoints are defined in `src/types/gateway.ts` and `src/index.ts`. Each endpoint consists of:
1818

19-
* a path definition
20-
* operation definition (params and response types)
21-
* response definition
22-
* a function that fetches the endpoint
19+
- a path definition
20+
- operation definition (params and response types)
21+
- response definition
22+
- a function that fetches the endpoint
2323

2424
To add a new endpoint, follow the pattern set by the existing endpoints.
2525

@@ -33,8 +33,8 @@ yarn eslint:fix
3333

3434
## Tests
3535

36-
To run the tests:
36+
To run the tests locally:
3737

3838
```
39-
jest test --watch
39+
yarn test
4040
```

babel.config.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
module.exports = {
2-
presets: [
3-
['@babel/preset-env', { targets: { node: 'current' } }],
4-
'@babel/preset-typescript',
5-
],
6-
};
2+
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
3+
}

e2e/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const config = {
2+
baseUrl: 'https://safe-client.staging.gnosisdev.com/v1',
3+
}
4+
5+
export default config

e2e/get-owned-safes.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { getOwnedSafes } from '../src'
2+
import config from './config'
3+
4+
describe('getOwnedSages tests', () => {
5+
it('should get owned safes on rinkeby', async () => {
6+
const data = await getOwnedSafes(config.baseUrl, '4', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDFf9')
7+
8+
expect(data).toEqual({
9+
safes: ['0x9B5dc27B104356516B05b02F6166a54F6D74e40B', '0xb3b83bf204C458B461de9B0CD2739DB152b4fa5A'],
10+
})
11+
})
12+
13+
it('should return an empty array if no owned safes', async () => {
14+
const data = await getOwnedSafes(config.baseUrl, '1', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDFf9')
15+
expect(data).toEqual({ safes: [] })
16+
})
17+
18+
it('should throw for bad addresses', async () => {
19+
const req = getOwnedSafes(config.baseUrl, '4', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDfF9')
20+
await expect(req).rejects.toThrow('1: Checksum address validation failed')
21+
})
22+
})

e2e/propose-transaction.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { proposeTransaction } from '../src'
2+
import config from './config'
3+
4+
describe('proposeTransaction tests', () => {
5+
it('should propose a transaction and fail', async () => {
6+
const req = proposeTransaction(config.baseUrl, '4', '0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7', {
7+
to: '0x49d4450977E2c95362C13D3a31a09311E0Ea26A6',
8+
value: '0',
9+
data: '0xe8dde2320000000000000000000000000000000000000000000000000000000000000000',
10+
operation: 0,
11+
nonce: '1',
12+
safeTxGas: '39557',
13+
baseGas: '0',
14+
gasPrice: '0',
15+
gasToken: '0x0000000000000000000000000000000000000000',
16+
refundReceiver: '0x0000000000000000000000000000000000000000',
17+
safeTxHash: '0x98798b6d9400b25397e85eb79c444a06f93d153555c1d7fd026176f02055a824',
18+
sender: '0x474e5Ded6b5D078163BFB8F6dBa355C3aA5478C8',
19+
origin: null,
20+
})
21+
await expect(req).rejects.toThrow(
22+
'1337: {"nonFieldErrors":["Tx with safe-tx-hash=0x98798b6d9400b25397e85eb79c444a06f93d153555c1d7fd026176f02055a824 for safe=0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7 was already executed in tx-hash=0x1baa941b8696ff3b0a8831f11da243a02f028122b6298ee61e3a1c0d5eeb171a"]}',
23+
)
24+
})
25+
})

e2e/safes-read.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { getSafeInfo } from '../src'
2+
import config from './config'
3+
4+
describe('getSafeInfo tests', () => {
5+
it('should get safe info on rinkeby', async () => {
6+
const address = '0x9B5dc27B104356516B05b02F6166a54F6D74e40B'
7+
const data = await getSafeInfo(config.baseUrl, '4', address)
8+
9+
expect(data.address.value).toBe(address)
10+
expect(data.guard).toBe(null)
11+
expect(data.nonce).toBe(3)
12+
expect(data.owners).toEqual([
13+
{
14+
value: '0x21D62C6894741DE97944D7844ED44D7782C66ABC',
15+
},
16+
{
17+
value: '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDFf9',
18+
},
19+
{
20+
value: '0x8814db983b821D65647C565fBf7c1092fC32437D',
21+
},
22+
{
23+
value: '0x474e5Ded6b5D078163BFB8F6dBa355C3aA5478C8',
24+
},
25+
])
26+
expect(data.threshold).toBe(1)
27+
expect(data.version).toBe('1.1.1')
28+
})
29+
})

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,4 @@ module.exports = {
191191

192192
// Whether to use watchman for file crawling
193193
// watchman: true,
194-
};
194+
}

0 commit comments

Comments
 (0)