1
+ import { describe , it } from "mocha"
2
+ import { assert } from "chai"
3
+ import * as config from "../src/config"
4
+
5
+ describe ( "Load configuration from JSON file" , ( ) => {
6
+ it ( "ethereum chain id is 1" , ( ) => {
7
+ const chains : config . Chains = config . Chains . load ( "production" )
8
+ const chainId : number = chains . ethereum . id
9
+ const expected = 1
10
+ assert . equal ( chainId , expected , `Expecting ethereum prod chain id to equal ${ expected } , got '${ chainId } '` )
11
+ } )
12
+ it ( "development chain id is 8995" , ( ) => {
13
+ const chains : config . Chains = config . Chains . load ( "development" )
14
+ const chainId : number = chains . ethereum . id
15
+ const expected = 8995
16
+ assert . equal ( chainId , expected , `Expecting ethereum dev chain id to equal ${ expected } , got '${ chainId } '` )
17
+ } )
18
+ it ( "reads DATA token dev address from JSON" , ( ) => {
19
+ const chains : config . Chains = config . Chains . load ( "development" )
20
+ const address = chains . ethereum . contracts [ "DATA-token" ]
21
+ const expected = "0xbAA81A0179015bE47Ad439566374F2Bae098686F"
22
+ assert . equal ( address , expected , `Expecting ethereum DATA token to equal ${ expected } , got '${ address } '` )
23
+ } )
24
+ it ( "reads prod Polygon RPC URL" , ( ) => {
25
+ const chains : config . Chains = config . Chains . load ( "production" )
26
+ const rpcHttpUrl = chains . polygon . rpcEndpoints [ 0 ] . url
27
+ const expected = "https://polygon-rpc.com"
28
+ assert . equal ( rpcHttpUrl , expected , `Expecting prod polygon RPC URL to equal ${ expected } , got '${ rpcHttpUrl } '` )
29
+ } )
30
+ it ( "finds RPC endpoints by protocol" , ( ) => {
31
+ const chains : config . Chains = config . Chains . load ( "production" )
32
+ const endpoints = chains . binance . getRPCEndpointsByProtocol ( config . RPCProtocol . HTTP )
33
+ assert . equal ( endpoints . length , 1 )
34
+ assert . equal ( endpoints [ 0 ] . url , "https://bsc-dataseed.binance.org" )
35
+ } )
36
+ } )
37
+ describe ( "Load configuration based on NODE_ENV environment variable" , ( ) => {
38
+ it ( "ethereum chain id is 1" , ( ) => {
39
+ process . env . NODE_ENV = "production"
40
+ const chains : config . Chains = config . Chains . loadFromNodeEnv ( )
41
+ const chainId : number = chains . ethereum . id
42
+ const expected = 1
43
+ assert . equal ( chainId , expected , `Expecting ethereum prod chain id to equal ${ expected } , got '${ chainId } '` )
44
+ } )
45
+ it ( "development chain id is 8995" , ( ) => {
46
+ process . env . NODE_ENV = "development"
47
+ const chains : config . Chains = config . Chains . loadFromNodeEnv ( )
48
+ const chainId : number = chains . ethereum . id
49
+ const expected = 8995
50
+ assert . equal ( chainId , expected , `Expecting ethereum dev chain id to equal ${ expected } , got '${ chainId } '` )
51
+ } )
52
+ it ( "errors when NODE_ENV is not set" , ( ) => {
53
+ delete process . env . NODE_ENV
54
+ assert . throws ( ( ) => {
55
+ /* eslint-disable @typescript-eslint/no-unused-vars */
56
+ const chains : config . Chains = config . Chains . loadFromNodeEnv ( )
57
+ } , / N O D E _ E N V e n v i r o n m e n t v a r i a b l e i s n o t s e t / )
58
+ } )
59
+ it ( "errors when NODE_ENV is something else than 'production' or 'development'" , ( ) => {
60
+ process . env . NODE_ENV = "dev"
61
+ assert . throws ( ( ) => {
62
+ /* eslint-disable @typescript-eslint/no-unused-vars */
63
+ const chains : config . Chains = config . Chains . loadFromNodeEnv ( )
64
+ } , / N O D E _ E N V e n v i r o n m e n t v a r i a b l e v a l u e m u s t b e e i t h e r ' p r o d u c t i o n ' o r ' d e v e l o p m e n t ' / )
65
+ } )
66
+ } )
0 commit comments