-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Encode slot chain id and add testing
- Loading branch information
Showing
6 changed files
with
286 additions
and
22 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,13 @@ | ||
import type { Config } from 'jest'; | ||
|
||
const config: Config = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
roots: ['<rootDir>/src'], | ||
testMatch: ['**/__tests__/**/*.test.ts'], | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
}; | ||
|
||
export default config; |
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
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,60 @@ | ||
import { constants, shortString } from "starknet"; | ||
import { parseChainId } from "../utils"; | ||
|
||
describe("parseChainId", () => { | ||
describe("Starknet chains", () => { | ||
test("identifies mainnet", () => { | ||
expect( | ||
parseChainId(new URL("https://api.cartridge.gg/x/starknet/mainnet")), | ||
).toBe(constants.StarknetChainId.SN_MAIN); | ||
}); | ||
|
||
test("identifies sepolia", () => { | ||
expect( | ||
parseChainId(new URL("https://api.cartridge.gg/x/starknet/sepolia")), | ||
).toBe(constants.StarknetChainId.SN_SEPOLIA); | ||
}); | ||
}); | ||
|
||
describe("Project-specific chains", () => { | ||
test("identifies slot chain", () => { | ||
expect( | ||
parseChainId(new URL("https://api.cartridge.gg/x/slot/katana")), | ||
).toBe(shortString.encodeShortString("WP_SLOT")); | ||
}); | ||
|
||
test("identifies slot chain on localhost", () => { | ||
expect(parseChainId(new URL("http://localhost:8001/x/slot/katana"))).toBe( | ||
shortString.encodeShortString("WP_SLOT"), | ||
); | ||
}); | ||
|
||
test("identifies slot chain with hyphenated name", () => { | ||
expect( | ||
parseChainId( | ||
new URL("https://api.cartridge.gg/x/my-slot-chain/katana"), | ||
), | ||
).toBe(shortString.encodeShortString("WP_MY_SLOT_CHAIN")); | ||
}); | ||
|
||
test("identifies slot mainnet chain", () => { | ||
expect( | ||
parseChainId(new URL("https://api.cartridge.gg/x/slot/mainnet")), | ||
).toBe(shortString.encodeShortString("GG_SLOT")); | ||
}); | ||
}); | ||
|
||
describe("Error cases", () => { | ||
test("throws error for unsupported URL format", () => { | ||
expect(() => | ||
parseChainId(new URL("https://api.example.com/unsupported")), | ||
).toThrow("Chain https://api.example.com/unsupported not supported"); | ||
}); | ||
|
||
test("throws error for URLs without proper chain identifiers", () => { | ||
expect(() => | ||
parseChainId(new URL("https://api.example.com/v1/starknet")), | ||
).toThrow("Chain https://api.example.com/v1/starknet not supported"); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.