Skip to content

Commit

Permalink
Add randomnet to known networks (#281)
Browse files Browse the repository at this point in the history
* add randomnet to known networks

* update changelog and add randomnet chainid

* add test for randomnet config
  • Loading branch information
0xaptosj authored Feb 8, 2024
1 parent ec9b1ed commit 0b159e9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/internal/ans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const NetworkToAnsContract: Record<Network, string | null> = {
[Network.LOCAL]: LOCAL_ANS_ACCOUNT_ADDRESS,
[Network.CUSTOM]: null,
[Network.DEVNET]: null,
[Network.RANDOMNET]: null,
};

function getRouterAddress(aptosConfig: AptosConfig): string {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/apiEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,46 @@ export const NetworkToIndexerAPI: Record<string, string> = {
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",
};

export const NetworkToNodeAPI: Record<string, string> = {
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",
};

export const NetworkToFaucetAPI: Record<string, string> = {
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",
};

export enum Network {
MAINNET = "mainnet",
TESTNET = "testnet",
DEVNET = "devnet",
RANDOMNET = "randomnet",
LOCAL = "local",
CUSTOM = "custom",
}

export const NetworkToChainId: Record<string, number> = {
mainnet: 1,
testnet: 2,
randomnet: 70,
};

export const NetworkToNetworkName: Record<string, Network> = {
mainnet: Network.MAINNET,
testnet: Network.TESTNET,
devnet: Network.DEVNET,
randomnet: Network.RANDOMNET,
local: Network.LOCAL,
custom: Network.CUSTOM,
};
24 changes: 23 additions & 1 deletion tests/unit/aptosConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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,
Expand Down

0 comments on commit 0b159e9

Please sign in to comment.