|
1 | | -import { beforeEach, describe, expect, it, vi } from 'vitest'; |
| 1 | +import { beforeEach, describe, expect, it, test, vi } from 'vitest'; |
2 | 2 | import { address } from '../fixtures/common'; |
3 | 3 | import { Address } from '../serializable/fxs/common'; |
4 | 4 | import { AddressMap, AddressMaps, matchOwners } from './addressMap'; |
@@ -245,67 +245,76 @@ describe('AddressMaps', () => { |
245 | 245 | }); |
246 | 246 |
|
247 | 247 | describe('matchOwners', () => { |
248 | | - it('matches owners', () => { |
249 | | - const owner1 = address(); |
250 | | - const owner2 = Address.fromHex('7db97c7cece249c2b98bdc0226cc4c2a57bf52fc'); |
251 | | - const ownerAddresses: Uint8Array[] = [owner1.toBytes(), owner2.toBytes()]; |
252 | | - const goodOwner = OutputOwners.fromNative(ownerAddresses, 0n, 1); |
253 | | - const threasholdTooHigh = OutputOwners.fromNative(ownerAddresses, 0n, 5); |
254 | | - const wrongOwner = OutputOwners.fromNative( |
255 | | - [hexToBuffer('0x12345123451234512345')], |
256 | | - 0n, |
257 | | - 5, |
258 | | - ); |
259 | | - const locked = OutputOwners.fromNative( |
260 | | - ownerAddresses, |
261 | | - 9999999999999999999999999999999999n, |
262 | | - 5, |
263 | | - ); |
| 248 | + const owner1 = address(); |
| 249 | + const owner2 = Address.fromHex('7db97c7cece249c2b98bdc0226cc4c2a57bf52fc'); |
| 250 | + const ownerAddresses: Uint8Array[] = [owner1.toBytes(), owner2.toBytes()]; |
| 251 | + // NOTE: the ownerAddresses will be sorted in the OutputOwners -- owner2 is at index 0. |
| 252 | + const goodOwner = OutputOwners.fromNative(ownerAddresses, 0n, 1); |
| 253 | + const goodOwnerMultisig = OutputOwners.fromNative(ownerAddresses, 0n, 2); |
| 254 | + const threasholdTooHigh = OutputOwners.fromNative(ownerAddresses, 0n, 5); |
| 255 | + const wrongOwner = OutputOwners.fromNative( |
| 256 | + [hexToBuffer('0x12345123451234512345')], |
| 257 | + 0n, |
| 258 | + 5, |
| 259 | + ); |
| 260 | + const locked = OutputOwners.fromNative( |
| 261 | + ownerAddresses, |
| 262 | + 9999999999999999999999999999999999n, |
| 263 | + 5, |
| 264 | + ); |
264 | 265 |
|
265 | | - const specs = [ |
266 | | - { |
267 | | - testCase: goodOwner, |
268 | | - expectedSigIndices: [0], |
269 | | - expectedAddressMap: new AddressMap([[owner1, 0]]), |
270 | | - }, |
271 | | - { |
272 | | - testCase: threasholdTooHigh, |
273 | | - expectedSigIndices: undefined, |
274 | | - expectedAddressMap: undefined, |
275 | | - }, |
276 | | - { |
277 | | - testCase: locked, |
278 | | - expectedSigIndices: undefined, |
279 | | - expectedAddressMap: undefined, |
280 | | - }, |
281 | | - { |
282 | | - testCase: wrongOwner, |
283 | | - expectedSigIndices: undefined, |
284 | | - expectedAddressMap: undefined, |
285 | | - }, |
286 | | - { |
287 | | - testCase: goodOwner, |
288 | | - sigindices: [1], |
289 | | - expectedSigIndices: [1], |
290 | | - expectedAddressMap: new AddressMap([[owner2, 1]]), |
291 | | - }, |
292 | | - { |
293 | | - testCase: goodOwner, |
294 | | - sigindices: [2], |
295 | | - expectedSigIndices: undefined, |
296 | | - expectedAddressMap: undefined, |
297 | | - }, |
298 | | - ]; |
| 266 | + const specs = [ |
| 267 | + { |
| 268 | + testCase: goodOwner, |
| 269 | + expectedSigIndices: [0], |
| 270 | + expectedAddressMap: new AddressMap([[owner2, 0]]), |
| 271 | + }, |
| 272 | + { |
| 273 | + testCase: threasholdTooHigh, |
| 274 | + expectedSigIndices: undefined, |
| 275 | + expectedAddressMap: undefined, |
| 276 | + }, |
| 277 | + { |
| 278 | + testCase: locked, |
| 279 | + expectedSigIndices: undefined, |
| 280 | + expectedAddressMap: undefined, |
| 281 | + }, |
| 282 | + { |
| 283 | + testCase: wrongOwner, |
| 284 | + expectedSigIndices: undefined, |
| 285 | + expectedAddressMap: undefined, |
| 286 | + }, |
| 287 | + { |
| 288 | + testCase: goodOwner, |
| 289 | + sigindices: [1], |
| 290 | + expectedSigIndices: [1], |
| 291 | + expectedAddressMap: new AddressMap([[owner1, 1]]), |
| 292 | + }, |
| 293 | + { |
| 294 | + testCase: goodOwnerMultisig, |
| 295 | + sigindices: [0, 1], |
| 296 | + expectedSigIndices: [0, 1], |
| 297 | + expectedAddressMap: new AddressMap([ |
| 298 | + [owner2, 0], |
| 299 | + [owner1, 1], |
| 300 | + ]), |
| 301 | + }, |
| 302 | + { |
| 303 | + testCase: goodOwner, |
| 304 | + sigindices: [2], |
| 305 | + expectedSigIndices: undefined, |
| 306 | + expectedAddressMap: undefined, |
| 307 | + }, |
| 308 | + ]; |
299 | 309 |
|
300 | | - specs.forEach((spec) => { |
301 | | - const result = matchOwners( |
302 | | - spec.testCase, |
303 | | - addressesFromBytes(ownerAddresses), |
304 | | - 50n, |
305 | | - spec.sigindices, |
306 | | - ); |
307 | | - expect(result?.sigIndicies).toEqual(spec.expectedSigIndices); |
308 | | - expect(result?.addressMap).toEqual(spec.expectedAddressMap); |
309 | | - }); |
| 310 | + test.each(specs)('matchOwners($testCase, $sigIndices)', (spec) => { |
| 311 | + const result = matchOwners( |
| 312 | + spec.testCase, |
| 313 | + addressesFromBytes(ownerAddresses), |
| 314 | + 50n, |
| 315 | + spec.sigindices, |
| 316 | + ); |
| 317 | + expect(result?.sigIndicies).toEqual(spec.expectedSigIndices); |
| 318 | + expect(result?.addressMap).toEqual(spec.expectedAddressMap); |
310 | 319 | }); |
311 | 320 | }); |
0 commit comments