• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-client-gateway-nest / 5941127155

22 Aug 2023 03:52PM UTC coverage: 92.245%. First build
5941127155

Pull #631

github

GitHub
Merge daff89e0f into c8aa71879
Pull Request #631:

966 of 1156 branches covered (83.56%)

Branch coverage included in aggregate %.

127 of 144 new or added lines in 22 files covered. (88.19%)

4494 of 4763 relevant lines covered (94.35%)

72.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/routes/data-decode/__tests__/data-decode.e2e-spec.ts
1
import { faker } from '@faker-js/faker';
×
2
import { INestApplication } from '@nestjs/common';
3
import { Test } from '@nestjs/testing';
×
4
import { RedisClientType } from 'redis';
5
import * as request from 'supertest';
×
6
import { AppModule } from '../../../app.module';
×
7
import { TestAppProvider } from '../../../__tests__/test-app.provider';
×
8
import { DataDecoded } from '../../../domain/data-decoder/entities/data-decoded.entity';
9
import { redisClientFactory } from '../../../__tests__/redis-client.factory';
×
10
import { getDataDecodedDtoBuilder } from '../entities/__tests__/get-data-decoded.dto.builder';
×
NEW
11
import { encodeFunctionData, formatUnits, parseAbi } from 'viem';
×
12

13
describe('Data decode e2e tests', () => {
×
14
  let app: INestApplication;
15
  let redisClient: RedisClientType;
16
  const chainId = '5'; // Görli testnet
×
17

18
  beforeAll(async () => {
×
19
    const moduleRef = await Test.createTestingModule({
×
20
      imports: [AppModule],
21
    }).compile();
22

23
    app = await new TestAppProvider().provide(moduleRef);
×
24
    await app.init();
×
25
    redisClient = await redisClientFactory();
×
26
  });
27

28
  beforeEach(async () => {
×
29
    await redisClient.flushAll();
×
30
  });
31

32
  it('POST /data-decoder', async () => {
×
33
    const getDataDecodedDto = getDataDecodedDtoBuilder()
×
34
      .with(
35
        'data',
36
        '0x8d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004a60031369c6ecb549c117aff789ad66c708a452296740000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000ccd7c90b85e48682a68e7db1dc1f0339ea46ab020000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000c20aef7964d6c3c966e3ae9e850aee9db81792e30000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000000bccd4163a8d714eaae683af53accc389fd73fdd0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000d50ef7b662a07d3fc934891e488b133313cbfd7d0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000e90975bd7b1937dfa4bf3d9c41368a07255607050000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000e817579b91ae59512ebdb860146001d170018e550000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000006cd68754b97db054b68397e27ddcdc16d27afb220000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000002ab2231d49154bb22b58df44b122ef9ba3ae97990000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000001ea33eb00f2c2f00e1021fd7e9dd22154c82b06f0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000844d2c79c4a721cbe153b092ba75b4c1e7cb2bc30000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000182ff57e69ec50eff8fc4a9e19e4d02d75061d320000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000b07d074825596798f6e127f86825aafaa81cdd7e0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000d39d0a6b980218038c4675310399cecebb54de600000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
37
      )
38
      .with('to', '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761')
39
      .build();
40
    const expectedResponse: DataDecoded = {
×
41
      method: 'multiSend',
42
      parameters: [
43
        {
44
          name: 'transactions',
45
          type: 'bytes',
46
          value:
47
            '0x0031369c6ecb549c117aff789ad66c708a452296740000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000ccd7c90b85e48682a68e7db1dc1f0339ea46ab020000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000c20aef7964d6c3c966e3ae9e850aee9db81792e30000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000000bccd4163a8d714eaae683af53accc389fd73fdd0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000d50ef7b662a07d3fc934891e488b133313cbfd7d0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000e90975bd7b1937dfa4bf3d9c41368a07255607050000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000e817579b91ae59512ebdb860146001d170018e550000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000006cd68754b97db054b68397e27ddcdc16d27afb220000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000002ab2231d49154bb22b58df44b122ef9ba3ae97990000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000001ea33eb00f2c2f00e1021fd7e9dd22154c82b06f0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000844d2c79c4a721cbe153b092ba75b4c1e7cb2bc30000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000182ff57e69ec50eff8fc4a9e19e4d02d75061d320000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000b07d074825596798f6e127f86825aafaa81cdd7e0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000d39d0a6b980218038c4675310399cecebb54de600000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000',
48
          valueDecoded: [
49
            {
50
              operation: 0,
51
              to: '0x31369C6ECB549C117aFF789Ad66C708A45229674',
52
              value: '1000000000000000000',
53
              data: null,
54
              dataDecoded: null,
55
            },
56
            {
57
              operation: 0,
58
              to: '0xccd7C90B85e48682A68E7Db1dC1F0339EA46Ab02',
59
              value: '1000000000000000000',
60
              data: null,
61
              dataDecoded: null,
62
            },
63
            {
64
              operation: 0,
65
              to: '0xc20AeF7964d6c3C966E3Ae9E850aEe9DB81792E3',
66
              value: '1000000000000000000',
67
              data: null,
68
              dataDecoded: null,
69
            },
70
            {
71
              operation: 0,
72
              to: '0x0bCcD4163a8D714EAAE683AF53accC389Fd73FDD',
73
              value: '1000000000000000000',
74
              data: null,
75
              dataDecoded: null,
76
            },
77
            {
78
              operation: 0,
79
              to: '0xD50EF7b662A07d3fc934891e488B133313cBFd7d',
80
              value: '1000000000000000000',
81
              data: null,
82
              dataDecoded: null,
83
            },
84
            {
85
              operation: 0,
86
              to: '0xe90975BD7B1937DfA4BF3d9c41368a0725560705',
87
              value: '1000000000000000000',
88
              data: null,
89
              dataDecoded: null,
90
            },
91
            {
92
              operation: 0,
93
              to: '0xE817579b91aE59512EbdB860146001D170018e55',
94
              value: '1000000000000000000',
95
              data: null,
96
              dataDecoded: null,
97
            },
98
            {
99
              operation: 0,
100
              to: '0x6cD68754B97DB054b68397E27ddcdC16D27AfB22',
101
              value: '1000000000000000000',
102
              data: null,
103
              dataDecoded: null,
104
            },
105
            {
106
              operation: 0,
107
              to: '0x2ab2231D49154bB22b58df44B122ef9BA3Ae9799',
108
              value: '1000000000000000000',
109
              data: null,
110
              dataDecoded: null,
111
            },
112
            {
113
              operation: 0,
114
              to: '0x1ea33eb00F2C2F00e1021FD7E9dD22154C82b06F',
115
              value: '1000000000000000000',
116
              data: null,
117
              dataDecoded: null,
118
            },
119
            {
120
              operation: 0,
121
              to: '0x844d2C79C4a721CBe153B092bA75B4c1E7Cb2BC3',
122
              value: '1000000000000000000',
123
              data: null,
124
              dataDecoded: null,
125
            },
126
            {
127
              operation: 0,
128
              to: '0x182FF57E69eC50eFF8fc4a9E19e4d02D75061D32',
129
              value: '1000000000000000000',
130
              data: null,
131
              dataDecoded: null,
132
            },
133
            {
134
              operation: 0,
135
              to: '0xB07d074825596798f6e127f86825AAFaA81Cdd7e',
136
              value: '1000000000000000000',
137
              data: null,
138
              dataDecoded: null,
139
            },
140
            {
141
              operation: 0,
142
              to: '0xd39d0a6b980218038C4675310399cecEbb54DE60',
143
              value: '1000000000000000000',
144
              data: null,
145
              dataDecoded: null,
146
            },
147
          ],
148
        },
149
      ],
150
      humanDescription: null,
151
    };
152

NEW
153
    await request(app.getHttpServer())
×
154
      .post(`/v1/chains/${chainId}/data-decoder`)
155
      .send(getDataDecodedDto)
156
      .expect(200)
157
      .then(({ body }) => {
NEW
158
        expect(body).toEqual(expectedResponse);
×
159
      });
160
  });
161

NEW
162
  it('POST /data-decoder should include humanDescription', async () => {
×
NEW
163
    const abi = parseAbi(['function transfer(address, uint256)']);
×
NEW
164
    const mockAmount = faker.number.bigInt();
×
NEW
165
    const mockTransferData = encodeFunctionData({
×
166
      abi,
167
      functionName: 'transfer',
168
      args: ['0x7a9af6Ef9197041A5841e84cB27873bEBd3486E2', mockAmount],
169
    });
170

NEW
171
    const getDataDecodedDto = getDataDecodedDtoBuilder()
×
172
      .with('data', mockTransferData)
173
      .with('to', '0x61fD3b6d656F39395e32f46E2050953376c3f5Ff')
174
      .build();
175

NEW
176
    const expectedResponse: DataDecoded = {
×
177
      humanDescription: `Send ${formatUnits(
178
        mockAmount,
179
        18,
180
      )} SAFE to 0x7a9a...86E2`,
181
      method: 'transfer',
182
      parameters: [
183
        {
184
          name: 'to',
185
          type: 'address',
186
          value: '0x7a9af6Ef9197041A5841e84cB27873bEBd3486E2',
187
        },
188
        {
189
          name: 'amount',
190
          type: 'uint256',
191
          value: Number(mockAmount).toString(),
192
        },
193
      ],
194
    };
195

196
    await request(app.getHttpServer())
×
197
      .post(`/v1/chains/${chainId}/data-decoder`)
198
      .send(getDataDecodedDto)
199
      .expect(200)
200
      .then(({ body }) => {
201
        expect(body).toEqual(expectedResponse);
×
202
      });
203
  });
204

205
  it('POST /data-decoder should throw a validation error', async () => {
×
206
    const getDataDecodedDto = getDataDecodedDtoBuilder().build();
×
207

208
    await request(app.getHttpServer())
×
209
      .post(`/v1/chains/${chainId}/data-decoder`)
210
      .send({ ...getDataDecodedDto, to: faker.number.int() })
211
      .expect(400)
212
      .expect({ message: 'Validation failed', code: 42, arguments: [] });
213
  });
214

215
  it('POST /data-decoder should throw a validation error (2)', async () => {
×
216
    const getDataDecodedDto = getDataDecodedDtoBuilder().build();
×
217

218
    await request(app.getHttpServer())
×
219
      .post(`/v1/chains/${chainId}/data-decoder`)
220
      .send({ ...getDataDecodedDto, to: faker.string.alphanumeric() })
221
      .expect(400)
222
      .expect({ message: 'Validation failed', code: 42, arguments: [] });
223
  });
224

225
  afterAll(async () => {
×
226
    await app.close();
×
227
    await redisClient.flushAll();
×
228
    await redisClient.quit();
×
229
  });
230
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc