-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
2,299 additions
and
198 deletions.
There are no files selected for viewing
Empty file.
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
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
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 |
---|---|---|
@@ -1,64 +1,84 @@ | ||
import { | ||
arbitrum, | ||
arbitrumSepolia, | ||
base, | ||
baseSepolia, | ||
bsc, | ||
type Chain, | ||
gnosis, | ||
holesky, | ||
linea, | ||
lineaSepolia, | ||
mainnet, | ||
optimism, | ||
optimismSepolia, | ||
polygon, | ||
scroll, | ||
scrollSepolia, | ||
sepolia, | ||
} from "viem/chains"; | ||
|
||
export enum ESupportedNetworks { | ||
ETHEREUM = "mainnet", | ||
OPTIMISM = "optimism", | ||
OPTIMISM_SEPOLIA = "optimism-sepolia", | ||
BSC = "bsc", | ||
BSC_CHAPEL = "chapel", | ||
GNOSIS_CHAIN = "gnosis", | ||
FUSE = "fuse", | ||
POLYGON = "matic", | ||
FANTOM_OPERA = "fantom", | ||
ZKSYNC_ERA_TESTNET = "zksync-era-testnet", | ||
BOBA = "boba", | ||
MOONBEAM = "moonbeam", | ||
MOONRIVER = "moonriver", | ||
MOONBASE_ALPHA = "mbase", | ||
FANTOM_TESTNET = "fantom-testnet", | ||
ARBITRUM_ONE = "arbitrum-one", | ||
CELO = "celo", | ||
AVALANCHE_FUJI = "fuji", | ||
AVALANCHE = "avalanche", | ||
CELO_ALFAJORES = "celo-alfajores", | ||
HOLESKY = "holesky", | ||
AURORA = "aurora", | ||
AURORA_TESTNET = "aurora-testnet", | ||
HARMONY = "harmony", | ||
LINEA_SEPOLIA = "linea-sepolia", | ||
GNOSIS_CHIADO = "gnosis-chiado", | ||
MODE_SEPOLIA = "mode-sepolia", | ||
MODE = "mode-mainnet", | ||
BASE_SEPOLIA = "base-sepolia", | ||
ZKSYNC_ERA_SEPOLIA = "zksync-era-sepolia", | ||
POLYGON_ZKEVM = "polygon-zkevm", | ||
ZKSYNC_ERA = "zksync-era", | ||
ETHEREUM_SEPOLIA = "sepolia", | ||
ARBITRUM_SEPOLIA = "arbitrum-sepolia", | ||
LINEA = "linea", | ||
BASE = "base", | ||
SCROLL_SEPOLIA = "scroll-sepolia", | ||
SCROLL = "scroll", | ||
BLAST_MAINNET = "blast-mainnet", | ||
ASTAR_ZKEVM_MAINNET = "astar-zkevm-mainnet", | ||
SEI_TESTNET = "sei-testnet", | ||
BLAST_TESTNET = "blast-testnet", | ||
ETHERLINK_TESTNET = "etherlink-testnet", | ||
XLAYER_SEPOLIA = "xlayer-sepolia", | ||
XLAYER_MAINNET = "xlayer-mainnet", | ||
POLYGON_AMOY = "polygon-amoy", | ||
ZKYOTO_TESTNET = "zkyoto-testnet", | ||
POLYGON_ZKEVM_CARDONA = "polygon-zkevm-cardona", | ||
SEI_MAINNET = "sei-mainnet", | ||
ROOTSTOCK_MAINNET = "rootstock", | ||
IOTEX_MAINNET = "iotex", | ||
NEAR_MAINNET = "near-mainnet", | ||
NEAR_TESTNET = "near-testnet", | ||
COSMOS = "cosmoshub-4", | ||
COSMOS_HUB = "theta-testnet-001", | ||
OSMOSIS = "osmosis-1", | ||
OSMO_TESTNET = "osmo-test-4", | ||
ARWEAVE = "arweave-mainnet", | ||
BITCOIN = "btc", | ||
SOLANA = "solana-mainnet-beta", | ||
INJECTIVE_MAINNET = "injective-mainnet", | ||
INJECTIVE_TESTNET = "injective-testnet", | ||
} | ||
|
||
/** | ||
* Get the Viem chain for a given network | ||
* | ||
* @param network - the network to get the chain for | ||
* @returns the Viem chain | ||
*/ | ||
export const viemChain = (network: ESupportedNetworks): Chain => { | ||
switch (network) { | ||
case ESupportedNetworks.ETHEREUM: | ||
return mainnet; | ||
case ESupportedNetworks.ETHEREUM_SEPOLIA: | ||
return sepolia; | ||
case ESupportedNetworks.ARBITRUM_ONE: | ||
return arbitrum; | ||
case ESupportedNetworks.ARBITRUM_SEPOLIA: | ||
return arbitrumSepolia; | ||
case ESupportedNetworks.BASE_SEPOLIA: | ||
return baseSepolia; | ||
case ESupportedNetworks.LINEA_SEPOLIA: | ||
return lineaSepolia; | ||
case ESupportedNetworks.SCROLL_SEPOLIA: | ||
return scrollSepolia; | ||
case ESupportedNetworks.SCROLL: | ||
return scroll; | ||
case ESupportedNetworks.BASE: | ||
return base; | ||
case ESupportedNetworks.HOLESKY: | ||
return holesky; | ||
case ESupportedNetworks.LINEA: | ||
return linea; | ||
case ESupportedNetworks.BSC: | ||
return bsc; | ||
case ESupportedNetworks.GNOSIS_CHAIN: | ||
return gnosis; | ||
case ESupportedNetworks.POLYGON: | ||
return polygon; | ||
case ESupportedNetworks.OPTIMISM: | ||
return optimism; | ||
case ESupportedNetworks.OPTIMISM_SEPOLIA: | ||
return optimismSepolia; | ||
default: | ||
throw new Error(`Unsupported network: ${network}`); | ||
} | ||
}; |
90 changes: 90 additions & 0 deletions
90
packages/coordinator/ts/deployer/__tests__/deployer.controller.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,90 @@ | ||
import { zeroAddress } from "viem"; | ||
Check failure on line 1 in packages/coordinator/ts/deployer/__tests__/deployer.controller.test.ts GitHub Actions / check (lint:ts)
|
||
import { DeployerService } from "../deployer.service"; | ||
import { DeployerController } from "../deployer.controller"; | ||
Check failure on line 3 in packages/coordinator/ts/deployer/__tests__/deployer.controller.test.ts GitHub Actions / check (lint:ts)
|
||
import { Test } from "@nestjs/testing"; | ||
import { ErrorCodes, ESupportedNetworks } from "../../common"; | ||
import { testMaciDeploymentConfig, testPollDeploymentConfig } from "./utils"; | ||
Check failure on line 6 in packages/coordinator/ts/deployer/__tests__/deployer.controller.test.ts GitHub Actions / check (lint:ts)
|
||
import { SessionKeysService } from "../../sessionKeys/sessionKeys.service"; | ||
import { CryptoService } from "../../crypto/crypto.service"; | ||
import { FileService } from "../../file/file.service"; | ||
|
||
describe("DeployerController", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
let deployerController: DeployerController; | ||
|
||
const mockDeployerService = { | ||
deployMaci: jest.fn(), | ||
deployPoll: jest.fn(), | ||
}; | ||
|
||
|
||
const defaultDeployMaciReturn: string = zeroAddress; | ||
const defaultDeployPollReturn: string = "0"; | ||
|
||
const deployerControllerFail = new DeployerController(new DeployerService(new SessionKeysService(new CryptoService(), new FileService()))) | ||
|
||
beforeEach(async () => { | ||
const app = await Test.createTestingModule({ | ||
controllers: [DeployerController], | ||
}) | ||
.useMocker((token) => { | ||
if (token === DeployerService) { | ||
mockDeployerService.deployMaci.mockResolvedValue(defaultDeployMaciReturn); | ||
mockDeployerService.deployPoll.mockResolvedValue(defaultDeployPollReturn); | ||
return mockDeployerService; | ||
} | ||
|
||
return jest.fn(); | ||
}) | ||
.compile(); | ||
|
||
deployerController = app.get<DeployerController>(DeployerController); | ||
}); | ||
|
||
describe("v1/deploy/maci", () => { | ||
test("should deploy all contract", async() => { | ||
const response = await deployerController.deployMACIContracts({ | ||
chain: ESupportedNetworks.OPTIMISM_SEPOLIA, | ||
approval: "", | ||
sessionKeyAddress: "0x", | ||
config: testMaciDeploymentConfig | ||
}); | ||
|
||
expect(response).toEqual(defaultDeployMaciReturn); | ||
}); | ||
|
||
test("should return 400 bad request when the service throws", async () => { | ||
await expect(deployerControllerFail.deployMACIContracts({ | ||
chain: ESupportedNetworks.OPTIMISM_SEPOLIA, | ||
approval: "", | ||
sessionKeyAddress: "0x", | ||
config: testMaciDeploymentConfig | ||
})).rejects.toThrow(ErrorCodes.DECRYPTION); | ||
}); | ||
}); | ||
|
||
describe("v1/deploy/poll", () => { | ||
test("should deploy a new poll", async () => { | ||
const response = await deployerController.deployPoll({ | ||
chain: ESupportedNetworks.OPTIMISM_SEPOLIA, | ||
approval: "", | ||
sessionKeyAddress: "0x", | ||
config: testPollDeploymentConfig | ||
}); | ||
|
||
expect(response).toEqual(defaultDeployPollReturn); | ||
}); | ||
|
||
test("should return 400 bad request when the service throws", async () => { | ||
await expect(deployerControllerFail.deployPoll({ | ||
chain: ESupportedNetworks.OPTIMISM_SEPOLIA, | ||
approval: "", | ||
sessionKeyAddress: "0x", | ||
config: testPollDeploymentConfig | ||
})).rejects.toThrow(ErrorCodes.MACI_NOT_DEPLOYED); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.