diff --git a/CHANGELOG.md b/CHANGELOG.md index da63a5a87..96e8ca005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T - Add optional `options` param to `getAccountEventsByCreationNumber` query for paginations and order by - Add more meaningful API error messages - Support automated account creation for sponsored transactions +- Add randomnet to known networks # 1.5.1 (2024-01-24) diff --git a/src/internal/ans.ts b/src/internal/ans.ts index 80fbc2b75..17300232c 100644 --- a/src/internal/ans.ts +++ b/src/internal/ans.ts @@ -76,6 +76,7 @@ const NetworkToAnsContract: Record = { [Network.LOCAL]: LOCAL_ANS_ACCOUNT_ADDRESS, [Network.CUSTOM]: null, [Network.DEVNET]: null, + [Network.RANDOMNET]: null, }; function getRouterAddress(aptosConfig: AptosConfig): string { diff --git a/src/utils/apiEndpoints.ts b/src/utils/apiEndpoints.ts index 59019f265..2858de818 100644 --- a/src/utils/apiEndpoints.ts +++ b/src/utils/apiEndpoints.ts @@ -5,6 +5,7 @@ export const NetworkToIndexerAPI: Record = { mainnet: "https://indexer.mainnet.aptoslabs.com/v1/graphql", testnet: "https://indexer-testnet.staging.gcp.aptosdev.com/v1/graphql", devnet: "https://indexer-devnet.staging.gcp.aptosdev.com/v1/graphql", + randomnet: "https://indexer-randomnet.hasura.app/v1/graphql", local: "http://127.0.0.1:8090/v1/graphql", }; @@ -12,6 +13,7 @@ export const NetworkToNodeAPI: Record = { mainnet: "https://fullnode.mainnet.aptoslabs.com/v1", testnet: "https://fullnode.testnet.aptoslabs.com/v1", devnet: "https://fullnode.devnet.aptoslabs.com/v1", + randomnet: "https://fullnode.random.aptoslabs.com/v1", local: "http://127.0.0.1:8080/v1", }; @@ -19,6 +21,7 @@ export const NetworkToFaucetAPI: Record = { mainnet: "https://faucet.mainnet.aptoslabs.com", testnet: "https://faucet.testnet.aptoslabs.com", devnet: "https://faucet.devnet.aptoslabs.com", + randomnet: "https://faucet.random.aptoslabs.com", local: "http://127.0.0.1:8081", }; @@ -26,6 +29,7 @@ export enum Network { MAINNET = "mainnet", TESTNET = "testnet", DEVNET = "devnet", + RANDOMNET = "randomnet", LOCAL = "local", CUSTOM = "custom", } @@ -33,12 +37,14 @@ export enum Network { export const NetworkToChainId: Record = { mainnet: 1, testnet: 2, + randomnet: 70, }; export const NetworkToNetworkName: Record = { mainnet: Network.MAINNET, testnet: Network.TESTNET, devnet: Network.DEVNET, + randomnet: Network.RANDOMNET, local: Network.LOCAL, custom: Network.CUSTOM, }; diff --git a/tests/unit/aptosConfig.test.ts b/tests/unit/aptosConfig.test.ts index 8e83ddd1f..64d4778ac 100644 --- a/tests/unit/aptosConfig.test.ts +++ b/tests/unit/aptosConfig.test.ts @@ -23,7 +23,7 @@ describe("aptos config", () => { expect(aptosConfig.getRequestUrl(AptosApiType.INDEXER)).toBe(NetworkToIndexerAPI[Network.LOCAL]); }); - test("it should set urls based on a given network", async () => { + test("it should set urls based on testnet", async () => { const settings: AptosSettings = { network: Network.TESTNET, }; @@ -34,6 +34,28 @@ describe("aptos config", () => { expect(aptosConfig.getRequestUrl(AptosApiType.INDEXER)).toBe(NetworkToIndexerAPI[Network.TESTNET]); }); + test("it should set urls based on mainnet", async () => { + const settings: AptosSettings = { + network: Network.MAINNET, + }; + const aptosConfig = new AptosConfig(settings); + expect(aptosConfig.network).toEqual("mainnet"); + expect(aptosConfig.getRequestUrl(AptosApiType.FULLNODE)).toBe(NetworkToNodeAPI[Network.MAINNET]); + expect(aptosConfig.getRequestUrl(AptosApiType.FAUCET)).toBe(NetworkToFaucetAPI[Network.MAINNET]); + expect(aptosConfig.getRequestUrl(AptosApiType.INDEXER)).toBe(NetworkToIndexerAPI[Network.MAINNET]); + }); + + test("it should set urls based on randomnet", async () => { + const settings: AptosSettings = { + network: Network.RANDOMNET, + }; + const aptosConfig = new AptosConfig(settings); + expect(aptosConfig.network).toEqual("randomnet"); + expect(aptosConfig.getRequestUrl(AptosApiType.FULLNODE)).toBe(NetworkToNodeAPI[Network.RANDOMNET]); + expect(aptosConfig.getRequestUrl(AptosApiType.FAUCET)).toBe(NetworkToFaucetAPI[Network.RANDOMNET]); + expect(aptosConfig.getRequestUrl(AptosApiType.INDEXER)).toBe(NetworkToIndexerAPI[Network.RANDOMNET]); + }); + test("it should have undefined urls when network is custom and no urls provided", async () => { const settings: AptosSettings = { network: Network.CUSTOM,