-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1337 from kadena-community/fix/incorrect-networkid
fix(pactjs-cli): fixed incorrect network by extracting data from api field
- Loading branch information
Showing
5 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@kadena/pactjs-cli': patch | ||
--- | ||
|
||
Extract networkId and chainId from the api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/tools/pactjs-cli/src/contract-generate/tests/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { extractNetworkAndChain } from '../utils'; | ||
|
||
describe('extractNetworkAndChain', () => { | ||
it('should return an empty object when api is undefined', () => { | ||
const result = extractNetworkAndChain(undefined); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should extract the network and chain from the api string', () => { | ||
const api = '/chainweb/0.0/mainnet01/'; | ||
const result = extractNetworkAndChain(api); | ||
expect(result).toEqual({ network: 'mainnet01', chain: undefined }); | ||
}); | ||
|
||
it('should return undefined for network and chain when api string does not match the pattern', () => { | ||
const api = '/chainweb/0.0/'; | ||
const result = extractNetworkAndChain(api); | ||
expect(result).toEqual({ network: undefined, chain: undefined }); | ||
}); | ||
|
||
it('should parse the chain number correctly when api string contains a different chain', () => { | ||
const api = 'http://api.com/chainweb/0.0/testnet04/chain/2/pact'; | ||
const result = extractNetworkAndChain(api); | ||
expect(result).toEqual({ network: 'testnet04', chain: 2 }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function extractNetworkAndChain(api?: string): { | ||
network?: string; | ||
chain?: number; | ||
} { | ||
if (api === undefined) return {}; | ||
const network = api.match(/\/chainweb\/\d+\.\d+\/(\w+)\//)?.[1]; | ||
const chain = api.match(/\/chain\/(\d+)\//)?.[1]; | ||
return { | ||
network, | ||
chain: chain !== undefined ? parseInt(chain, 10) : undefined, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters