|
15 | 15 | package byron_test
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "encoding/json" |
18 | 19 | "reflect"
|
| 20 | + "strconv" |
19 | 21 | "strings"
|
20 | 22 | "testing"
|
21 | 23 |
|
@@ -97,7 +99,6 @@ const byronGenesisConfig = `
|
97 | 99 | `
|
98 | 100 |
|
99 | 101 | var expectedGenesisObj = byron.ByronGenesis{
|
100 |
| - // TODO |
101 | 102 | AvvmDistr: map[string]string{
|
102 | 103 | "-0BJDi-gauylk4LptQTgjMeo7kY9lTCbZv12vwOSTZk=": "9999300000000",
|
103 | 104 | "-0Np4pyTOWF26iXWVIvu6fhz9QupwWRS2hcCaOEYlw0=": "3760024000000",
|
@@ -188,7 +189,7 @@ var expectedGenesisObj = byron.ByronGenesis{
|
188 | 189 | Omega: 0,
|
189 | 190 | },
|
190 | 191 | },
|
191 |
| - NonAvvmBalances: map[string]interface{}{}, |
| 192 | + NonAvvmBalances: map[string]string{}, |
192 | 193 | VssCerts: map[string]byron.ByronGenesisVssCert{
|
193 | 194 | "0efd6f3b2849d5baf25b3e2bf2d46f88427b4e455fc3dc43f57819c5": {
|
194 | 195 | ExpiryEpoch: 5,
|
@@ -250,3 +251,81 @@ func TestGenesisFromJson(t *testing.T) {
|
250 | 251 | )
|
251 | 252 | }
|
252 | 253 | }
|
| 254 | + |
| 255 | +func TestGenesisNonAvvmUtxos(t *testing.T) { |
| 256 | + testAddr := "FHnt4NL7yPXvDWHa8bVs73UEUdJd64VxWXSFNqetECtYfTd9TtJguJ14Lu3feth" |
| 257 | + testAmount := uint64(30_000_000_000_000_000) |
| 258 | + expectedTxId := "4843cf2e582b2f9ce37600e5ab4cc678991f988f8780fed05407f9537f7712bd" |
| 259 | + // Generate genesis config JSON |
| 260 | + tmpGenesisData := map[string]any{ |
| 261 | + "nonAvvmBalances": map[string]string{ |
| 262 | + testAddr: strconv.FormatUint(testAmount, 10), |
| 263 | + }, |
| 264 | + } |
| 265 | + tmpGenesisJson, err := json.Marshal(tmpGenesisData) |
| 266 | + if err != nil { |
| 267 | + t.Fatalf("unexpected error: %s", err) |
| 268 | + } |
| 269 | + // Parse genesis config JSON |
| 270 | + tmpGenesis, err := byron.NewByronGenesisFromReader( |
| 271 | + strings.NewReader(string(tmpGenesisJson)), |
| 272 | + ) |
| 273 | + tmpGenesisUtxos, err := tmpGenesis.GenesisUtxos() |
| 274 | + if err != nil { |
| 275 | + t.Fatalf("unexpected error: %s", err) |
| 276 | + } |
| 277 | + if len(tmpGenesisUtxos) != 1 { |
| 278 | + t.Fatalf("did not get expected count of genesis UTxOs") |
| 279 | + } |
| 280 | + tmpUtxo := tmpGenesisUtxos[0] |
| 281 | + if tmpUtxo.Id.Id().String() != expectedTxId { |
| 282 | + t.Fatalf("did not get expected TxID: got %s, wanted %s", tmpUtxo.Id.Id().String(), expectedTxId) |
| 283 | + } |
| 284 | + if tmpUtxo.Output.Address().String() != testAddr { |
| 285 | + t.Fatalf("did not get expected address: got %s, wanted %s", tmpUtxo.Output.Address().String(), testAddr) |
| 286 | + } |
| 287 | + if tmpUtxo.Output.Amount() != testAmount { |
| 288 | + t.Fatalf("did not get expected amount: got %d, wanted %d", tmpUtxo.Output.Amount(), testAmount) |
| 289 | + } |
| 290 | +} |
| 291 | + |
| 292 | +func TestGenesisAvvmUtxos(t *testing.T) { |
| 293 | + testPubkey := "URVk8FxX6Ik9z-Cub09oOxMkp6FwNq27kJUXbjJnfsQ=" |
| 294 | + testAmount := uint64(2463071701000000) |
| 295 | + expectedTxId := "0ae3da29711600e94a33fb7441d2e76876a9a1e98b5ebdefbf2e3bc535617616" |
| 296 | + expectedAddr := "Ae2tdPwUPEZKQuZh2UndEoTKEakMYHGNjJVYmNZgJk2qqgHouxDsA5oT83n" |
| 297 | + // Generate genesis config JSON |
| 298 | + tmpGenesisData := map[string]any{ |
| 299 | + "avvmDistr": map[string]string{ |
| 300 | + testPubkey: strconv.FormatUint(testAmount, 10), |
| 301 | + }, |
| 302 | + } |
| 303 | + tmpGenesisJson, err := json.Marshal(tmpGenesisData) |
| 304 | + if err != nil { |
| 305 | + t.Fatalf("unexpected error: %s", err) |
| 306 | + } |
| 307 | + // Parse genesis config JSON |
| 308 | + tmpGenesis, err := byron.NewByronGenesisFromReader( |
| 309 | + strings.NewReader(string(tmpGenesisJson)), |
| 310 | + ) |
| 311 | + if err != nil { |
| 312 | + t.Fatalf("unexpected error: %s", err) |
| 313 | + } |
| 314 | + tmpGenesisUtxos, err := tmpGenesis.GenesisUtxos() |
| 315 | + if err != nil { |
| 316 | + t.Fatalf("unexpected error: %s", err) |
| 317 | + } |
| 318 | + if len(tmpGenesisUtxos) != 1 { |
| 319 | + t.Fatalf("did not get expected count of genesis UTxOs") |
| 320 | + } |
| 321 | + tmpUtxo := tmpGenesisUtxos[0] |
| 322 | + if tmpUtxo.Id.Id().String() != expectedTxId { |
| 323 | + t.Fatalf("did not get expected TxID: got %s, wanted %s", tmpUtxo.Id.Id().String(), expectedTxId) |
| 324 | + } |
| 325 | + if tmpUtxo.Output.Address().String() != expectedAddr { |
| 326 | + t.Fatalf("did not get expected address: got %s, wanted %s", tmpUtxo.Output.Address().String(), expectedAddr) |
| 327 | + } |
| 328 | + if tmpUtxo.Output.Amount() != testAmount { |
| 329 | + t.Fatalf("did not get expected amount: got %d, wanted %d", tmpUtxo.Output.Amount(), testAmount) |
| 330 | + } |
| 331 | +} |
0 commit comments