github.com/smartcontractkit/chainlink-terra@v0.1.4/tests/e2e/rdd.go (about) 1 package e2e 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "os" 7 8 "github.com/rs/zerolog/log" 9 "github.com/smartcontractkit/terra.go/key" 10 "github.com/smartcontractkit/terra.go/msg" 11 ) 12 13 type RddConfig struct { 14 Apis map[string]interface{} `json:"apis"` 15 Contracts map[string]interface{} `json:"contracts"` 16 Flags map[string]interface{} `json:"flags"` 17 Network map[string]interface{} `json:"network"` 18 Operators map[string]interface{} `json:"operators"` 19 Proxies map[string]interface{} `json:"proxies"` 20 Validators map[string]interface{} `json:"validators"` 21 } 22 23 // WriteRdd writes the rdd data to a file 24 func WriteRdd(rdd *RddConfig, file string) error { 25 f, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) 26 if err != nil { 27 return err 28 } 29 defer f.Close() 30 31 j, err := json.Marshal(rdd) 32 if err != nil { 33 return err 34 } 35 log.Info().Str("Out", string(j)).Msg("The stuff we are writing") 36 37 _, err = f.Write(j) 38 39 return err 40 } 41 42 // NewChainlinkTerraEnv returns a cluster config with LocalTerra node 43 func NewRddContract(contractId string) *RddConfig { 44 rdd := &RddConfig{ 45 Apis: map[string]interface{}{}, 46 Contracts: map[string]interface{}{ 47 contractId: map[string]interface{}{ 48 "billing": map[string]interface{}{ 49 "observationPaymentGjuels": "1", 50 "recommendedGasPriceMicro": "1.1", 51 "transmissionPaymentGjuels": "1", 52 }, 53 "config": map[string]interface{}{ 54 "deltaGrace": "1s", 55 "deltaProgress": "12s", 56 "deltaResend": "30s", 57 "deltaRound": "10s", 58 "deltaStage": "14s", 59 "f": 1, 60 "maxDurationObservation": "1s", 61 "maxDurationQuery": "1s", 62 "maxDurationReport": "5s", 63 "maxDurationShouldAcceptFinalizedReport": "1s", 64 "maxDurationShouldTransmitAcceptedReport": "1s", 65 "rMax": 6, 66 "reportingPluginConfig": map[string]interface{}{ 67 "alphaAcceptInfinite": true, 68 "alphaAcceptPpb": "3000000", 69 "alphaReportInfinite": true, 70 "alphaReportPpb": "3000000", 71 "deltaC": "50s", 72 }, 73 "s": []int{ 74 1, 75 1, 76 2, 77 2, 78 }, 79 }, 80 "contractVersion": 6, 81 "decimals": 8, 82 "docsHidden": true, 83 "externalAdapterRequestParams": map[string]interface{}{ 84 "from": "ETH", 85 "to": "USD", 86 }, 87 "marketing": map[string]interface{}{ 88 "decimalPlaces": 2, 89 "formatDecimalPlaces": 0, 90 "history": true, 91 "pair": []string{ 92 "ETH", 93 "USD", 94 }, 95 "path": "eth-usd-ocr2", 96 }, 97 "maxSubmissionValue": "99999999999999999999999999999", 98 "minSubmissionValue": "0", 99 "name": "ETH / USD", 100 "oracles": []interface{}{ 101 newOracle("node-1"), 102 newOracle("node-2"), 103 newOracle("node-3"), 104 newOracle("node-4"), 105 }, 106 "status": "live", 107 "type": "numerical_median_feed", 108 }, 109 }, 110 Flags: map[string]interface{}{}, 111 Network: map[string]interface{}{}, 112 Operators: map[string]interface{}{ 113 "node-1": newOperator("node-1", 1), 114 "node-2": newOperator("node-2", 2), 115 "node-3": newOperator("node-3", 3), 116 "node-4": newOperator("node-4", 4), 117 }, 118 Proxies: map[string]interface{}{}, 119 Validators: map[string]interface{}{}, 120 } 121 return rdd 122 } 123 124 func newOperator(nodeName string, index int) map[string]interface{} { 125 // create a public key node address 126 mnemonic, _ := key.CreateMnemonic() 127 privKeyBz, _ := key.DerivePrivKeyBz(mnemonic, key.CreateHDPath(0, 0)) 128 privKey, _ := key.PrivKeyGen(privKeyBz) 129 addr := msg.AccAddress(privKey.PubKey().Address()) 130 131 return map[string]interface{}{ 132 "displayName": nodeName, 133 "adminAddress": "terra1mskaupg53dc8jh50nstcjmctm4sud9fc2t8rjn", 134 "csaKeys": []interface{}{ 135 map[string]interface{}{ 136 "nodeAddress": "terra1mskaupg53dc8jh50nstcjmctm4sud9fc2t8rjn", 137 "nodeName": "node 1", 138 "publicKey": fmt.Sprintf("c880f65f9e2118063c1e61b5f54c84c80651f2b8a367f46d3dbfbad4966c7f8%v", index), 139 }, 140 }, 141 "ocr2ConfigPublicKey": []interface{}{ 142 fmt.Sprintf("ocr2cfg_terra_b90e50daf82024624549e7708199dd05b6de8e10d6df62cd27581c65e5096b2%v", index), 143 }, 144 "ocr2OffchainPublicKey": []interface{}{ 145 fmt.Sprintf("ocr2off_terra_3bdd39af448a824cb6042b981274baf26f7501f2918ae825afc51a2442ef699%v", index), 146 }, 147 "ocr2OnchainPublicKey": []interface{}{ 148 fmt.Sprintf("ocr2on_terra_9c41de50e875fbca65643ffe60f90e84f1b9b4871092b7c3cbf4eff4b07e454%v", index), 149 }, 150 "ocrNodeAddress": []interface{}{ 151 addr, 152 }, 153 "peerId": []interface{}{ 154 fmt.Sprintf("12D3KooWHzGXm2NSRgYcn6B3szqfEr486kq2ipAEPXdqmE6nE2a%v", index), 155 }, 156 "status": "active", 157 } 158 } 159 160 func newOracle(nodeName string) map[string]interface{} { 161 return map[string]interface{}{ 162 "api": []string{ 163 nodeName, 164 }, 165 "operator": nodeName, 166 } 167 }