Skip to content

Commit

Permalink
Add predefined network for Testnet 2 (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan-SL committed Nov 30, 2022
1 parent 3183645 commit ff9b4b6
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ module.exports = {

you can use it by calling `npx hardhat starknet-deploy --starknet-network myNetwork`.

The Alpha networks and integrated Devnet are available by default, you don't need to define them in the config file; just pass:
The AlphaGoerli networks and integrated Devnet are available by default, you don't need to define them in the config file; just pass:

- `--starknet-network alpha` or `--starknet-network alpha-goerli` for Alpha Testnet (on Goerli)
- `--starknet-network alphaGoerli` or `--starknet-network alpha-goerli` for AlphaGoerli Testnet (on Goerli)
- `--starknet-network alpha-mainnet` for Alpha Mainnet
- `--starknet-network integrated-devnet` for integrated Devnet

Expand All @@ -123,7 +123,7 @@ npx hardhat starknet-verify [--starknet-network <NAME>] [--path <PATH>] [<DEPEND

Queries [Voyager](https://voyager.online/) to [verify the contract](https://voyager.online/verifyContract) deployed at `<CONTRACT_ADDRESS>` using the source files at `<PATH>` and any number of `<DEPENDENCY_PATH>`.

Like in the previous command, this plugin relies on `--starknet-network`, but will default to 'alpha' network in case this parameter is not passed.
Like in the previous command, this plugin relies on `--starknet-network`, but will default to 'alphaGoerli' network in case this parameter is not passed.

The verifier expects `<COMPILER_VERSION>` to be passed on request. Supported compiler versions are listed [here](https://voyager.online/verifyContract) in the dropdown menu.

Expand Down
7 changes: 6 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ export const CAIRO_CLI_DOCKER_REPOSITORY_WITH_TAG = `${CAIRO_CLI_DOCKER_REPOSITO
export const ACCOUNT_ARTIFACTS_DIR = "account-contract-artifacts";

export const ALPHA_TESTNET = "alpha-goerli";
export const ALPHA_TESTNET_INTERNALLY = "alpha";
export const ALPHA_TESTNET_2 = "alpha-goerli2";
export const ALPHA_TESTNET_INTERNALLY = "alphaGoerli";
export const ALPHA_TESTNET_2_INTERNALLY = "alphaGoerli2";
export const ALPHA_MAINNET = "alpha-mainnet";
export const ALPHA_MAINNET_INTERNALLY = "alphaMainnet";
export const DEFAULT_STARKNET_NETWORK = ALPHA_TESTNET_INTERNALLY;
export const ALPHA_URL = "https://alpha4.starknet.io";
export const ALPHA_GOERLI_URL_2 = "https://alpha4-2.starknet.io";
export const ALPHA_MAINNET_URL = "https://alpha-mainnet.starknet.io";
export const INTEGRATED_DEVNET = "integrated-devnet";
export const INTEGRATED_DEVNET_INTERNALLY = "integratedDevnet";

export const VOYAGER_GOERLI_CONTRACT_API_URL = "https://goerli.voyager.online/api/contract/";
export const VOYAGER_GOERLI_VERIFIED_URL = "https://goerli.voyager.online/contract/";
export const VOYAGER_GOERLI_2_CONTRACT_API_URL = "https://goerli-2.voyager.online/api/contract";
export const VOYAGER_GOERLI_2_VERIFIED_URL = "https://goerli-2.voyager.online/contract/";
export const VOYAGER_MAINNET_CONTRACT_API_URL = "https://voyager.online/api/contract/";
export const VOYAGER_MAINNET_VERIFIED_URL = "https://voyager.online/contract/";

Expand Down
18 changes: 15 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import {
CAIRO_CLI_DEFAULT_DOCKER_IMAGE_TAG,
CAIRO_CLI_DOCKER_REPOSITORY,
ALPHA_URL,
ALPHA_GOERLI_URL_2,
ALPHA_MAINNET_URL,
VOYAGER_GOERLI_CONTRACT_API_URL,
VOYAGER_MAINNET_CONTRACT_API_URL,
DEFAULT_STARKNET_NETWORK,
INTEGRATED_DEVNET_URL,
VOYAGER_GOERLI_VERIFIED_URL,
VOYAGER_MAINNET_VERIFIED_URL
VOYAGER_MAINNET_VERIFIED_URL,
VOYAGER_GOERLI_2_CONTRACT_API_URL,
VOYAGER_GOERLI_2_VERIFIED_URL
} from "./constants";
import {
getAccountPath,
Expand Down Expand Up @@ -112,15 +115,24 @@ extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) =>

// add url to alpha network
extendConfig((config: HardhatConfig) => {
if (!config.networks.alpha) {
config.networks.alpha = getDefaultHttpNetworkConfig(
if (!config.networks.alphaGoerli) {
config.networks.alphaGoerli = getDefaultHttpNetworkConfig(
ALPHA_URL,
VOYAGER_GOERLI_CONTRACT_API_URL,
VOYAGER_GOERLI_VERIFIED_URL,
StarknetChainId.TESTNET
);
}

if (!config.networks.alphaGoerli2) {
config.networks.alphaGoerli2 = getDefaultHttpNetworkConfig(
ALPHA_GOERLI_URL_2,
VOYAGER_GOERLI_2_CONTRACT_API_URL,
VOYAGER_GOERLI_2_VERIFIED_URL,
StarknetChainId.TESTNET
);
}

if (!config.networks.alphaMainnet) {
config.networks.alphaMainnet = getDefaultHttpNetworkConfig(
ALPHA_MAINNET_URL,
Expand Down
2 changes: 2 additions & 0 deletions src/starknet_cli_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@

NETWORKS = {
"alpha-goerli": "alpha4.starknet.io",
"alpha-goerli2": "alpha4-2.starknet.io",
"alpha-mainnet": "alpha-mainnet.starknet.io",
}

CHAIN_IDS = {
"alpha-goerli": StarknetChainId.TESTNET.value,
"alpha-goerli2": StarknetChainId.TESTNET.value,
"alpha-mainnet": StarknetChainId.MAINNET.value,
}

Expand Down
3 changes: 2 additions & 1 deletion src/type-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ declare module "hardhat/types/config" {
}

export interface NetworksConfig {
alpha: HttpNetworkConfig;
alphaGoerli: HttpNetworkConfig;
alphaGoerli2: HttpNetworkConfig;
alphaMainnet: HttpNetworkConfig;
integratedDevnet: HardhatNetworkConfig;
}
Expand Down
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
ALPHA_MAINNET_INTERNALLY,
ALPHA_TESTNET,
ALPHA_TESTNET_INTERNALLY,
ALPHA_TESTNET_2,
ALPHA_TESTNET_2_INTERNALLY,
DEFAULT_STARKNET_ACCOUNT_PATH,
INTEGRATED_DEVNET,
INTEGRATED_DEVNET_INTERNALLY
Expand Down Expand Up @@ -146,6 +148,8 @@ export function getNetwork<N extends NetworkConfig>(
networkName = ALPHA_MAINNET_INTERNALLY;
} else if (isTestnet(networkName)) {
networkName = ALPHA_TESTNET_INTERNALLY;
} else if (isTestnetTwo(networkName)) {
networkName = ALPHA_TESTNET_2_INTERNALLY;
} else if (isStarknetDevnet(networkName)) {
networkName = INTEGRATED_DEVNET_INTERNALLY;
}
Expand All @@ -169,6 +173,10 @@ function isTestnet(networkName: string): boolean {
return networkName === ALPHA_TESTNET || networkName === ALPHA_TESTNET_INTERNALLY;
}

function isTestnetTwo(networkName: string): boolean {
return networkName === ALPHA_TESTNET_2 || networkName === ALPHA_TESTNET_2_INTERNALLY;
}

function isMainnet(networkName: string): boolean {
return networkName === ALPHA_MAINNET || networkName === ALPHA_MAINNET_INTERNALLY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@shardlabs/starknet-hardhat-plugin";

module.exports = {
starknet: {
network: "alpha"
network: "alphaGoerli2"
},
networks: {
devnet: {
Expand Down
7 changes: 7 additions & 0 deletions test/configuration-tests/with-networks/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ process.env.NETWORK = invalidNetwork;
execution = hardhatStarknetTest("--no-compile test/contract-factory-test.ts".split(" "), true);
assertContains(execution.stderr, expected);
console.log("Success");

console.log("Testing with alpha-goerli2 config network");
hardhatStarknetDeploy(
"starknet-artifacts/contracts/contract.cairo --starknet-network alpha-goerli2 --inputs 10".split(
" "
)
);
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Error in plugin Starknet: Invalid network provided in starknet-network: foo.
Valid hardhat networks: hardhat, localhost, devnet, alpha, alphaMainnet, integratedDevnet
Valid hardhat networks: hardhat, localhost, devnet, alphaGoerli, alphaGoerli2, alphaMainnet, integratedDevnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error in plugin Starknet: Invalid network provided in starknet.network in hardhat.config: foo.
Valid hardhat networks: hardhat, localhost, devnet, alpha, alphaMainnet, integratedDevnet
Valid hardhat networks: hardhat, localhost, devnet, alphaGoerli, alphaGoerli2, alphaMainnet, integratedDevnet

For more info run Hardhat with --show-stack-traces
2 changes: 1 addition & 1 deletion test/general-tests/account-test/network.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../../network.schema",
"alpha": true,
"alphaGoerli2": true,
"devnet": true
}
2 changes: 1 addition & 1 deletion test/general-tests/declare-test/network.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../../network.schema",
"alpha": true,
"alphaGoerli2": true,
"devnet": true
}
2 changes: 1 addition & 1 deletion test/general-tests/plain/network.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../../network.schema",
"alpha": true,
"alphaGoerli2": true,
"devnet": true
}
4 changes: 3 additions & 1 deletion test/general-tests/starknet-verify/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ console.log("Sleeping to allow Voyager to register the verification");
exec("sleep 15s");

(async () => {
const { data } = await axios.get(`https://goerli.voyager.online/api/contract/${address}/code`);
const { data } = await axios.get(
`https://goerli-2.voyager.online/api/contract/${address}/code`
);
assertEqual(data.abiVerified, "true", "Contract is not verified");
})();
2 changes: 1 addition & 1 deletion test/general-tests/starknet-verify/network.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "../../network.schema",
"alpha": true
"alphaGoerli2": true
}
2 changes: 1 addition & 1 deletion test/network.schema
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"devnet": {
"type": "boolean"
},
"alpha": {
"alphaGoerli2": {
"type": "boolean"
},
"integrated-devnet": {
Expand Down
2 changes: 1 addition & 1 deletion test/venv-tests/with-venv-active/network.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../../network.schema",
"alpha": true,
"alphaGoerli2": true,
"devnet": true
}
2 changes: 1 addition & 1 deletion test/venv-tests/with-venv/network.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../../network.schema",
"alpha": true,
"alphaGoerli2": true,
"devnet": true
}

0 comments on commit ff9b4b6

Please sign in to comment.