LoadTestnet loads a testnet from a manifest file, using the filename to determine the testnet name and directory (from the basename of the file). The testnet generation must be deterministic, since it is generated separately by the runner and the test cases. For this reason, testnets use a random se
(file string)
| 108 | // separately by the runner and the test cases. For this reason, testnets use a |
| 109 | // random seed to generate e.g. keys. |
| 110 | func LoadTestnet(file string) (*Testnet, error) { |
| 111 | manifest, err := LoadManifest(file) |
| 112 | if err != nil { |
| 113 | return nil, err |
| 114 | } |
| 115 | dir := strings.TrimSuffix(file, filepath.Ext(file)) |
| 116 | |
| 117 | // Set up resource generators. These must be deterministic. |
| 118 | netAddress := networkIPv4 |
| 119 | if manifest.IPv6 { |
| 120 | netAddress = networkIPv6 |
| 121 | } |
| 122 | _, ipNet, err := net.ParseCIDR(netAddress) |
| 123 | if err != nil { |
| 124 | return nil, fmt.Errorf("invalid IP network address %q: %w", netAddress, err) |
| 125 | } |
| 126 | |
| 127 | ipGen := newIPGenerator(ipNet) |
| 128 | keyGen := newKeyGenerator(randomSeed) |
| 129 | proxyPortGen := newPortGenerator(proxyPortFirst) |
| 130 | |
| 131 | testnet := &Testnet{ |
| 132 | Name: filepath.Base(dir), |
| 133 | File: file, |
| 134 | Dir: dir, |
| 135 | IP: ipGen.Network(), |
| 136 | InitialHeight: 1, |
| 137 | InitialState: manifest.InitialState, |
| 138 | Validators: map[*Node]int64{}, |
| 139 | ValidatorUpdates: map[int64]map[*Node]int64{}, |
| 140 | Nodes: []*Node{}, |
| 141 | Evidence: manifest.Evidence, |
| 142 | KeyType: "ed25519", |
| 143 | LogLevel: manifest.LogLevel, |
| 144 | TxSize: manifest.TxSize, |
| 145 | ABCIProtocol: manifest.ABCIProtocol, |
| 146 | } |
| 147 | if len(manifest.KeyType) != 0 { |
| 148 | testnet.KeyType = manifest.KeyType |
| 149 | } |
| 150 | if testnet.TxSize <= 0 { |
| 151 | testnet.TxSize = 1024 |
| 152 | } |
| 153 | if manifest.InitialHeight > 0 { |
| 154 | testnet.InitialHeight = manifest.InitialHeight |
| 155 | } |
| 156 | if testnet.ABCIProtocol == "" { |
| 157 | testnet.ABCIProtocol = string(ProtocolBuiltin) |
| 158 | } |
| 159 | |
| 160 | // Set up nodes, in alphabetical order (IPs and ports get same order). |
| 161 | nodeNames := []string{} |
| 162 | for name := range manifest.Nodes { |
| 163 | nodeNames = append(nodeNames, name) |
| 164 | } |
| 165 | sort.Strings(nodeNames) |
| 166 | |
| 167 | for _, name := range nodeNames { |
nothing calls this directly
no test coverage detected
searching dependent graphs…