55 "encoding/json"
66 "fmt"
77 "io"
8+ "math/big"
89 "net/http"
910 "os"
1011 "testing"
@@ -507,14 +508,19 @@ func TestSeedNodeConfigurationWithOneNode(t *testing.T) {
507508 verifyPeerConfiguration (t , c .Validators [1 ], "validator" , false , true )
508509 verifyPeerConfiguration (t , c .Nodes [0 ], "node" , false , false ) // seed node should not have the seed flag set
509510}
510-
511- func TestGenesisAlteration (t * testing.T ) {
511+ func TestUpdateGenesisAccounts (t * testing.T ) {
512512 bz , err := os .ReadFile ("internal/testdata/testgenesis.json" )
513513 require .NoError (t , err )
514514
515515 var data map [string ]any
516516 require .NoError (t , json .Unmarshal (bz , & data ))
517517
518+ // Get original account count
519+ appstate := data ["app_state" ].(map [string ]any )
520+ auth := appstate ["auth" ].(map [string ]any )
521+ originalAccounts := auth ["accounts" ].([]any )
522+ originalCount := len (originalAccounts )
523+
518524 accounts := []chain.Account {
519525 {
520526 Type : "/foobar" ,
@@ -535,14 +541,45 @@ func TestGenesisAlteration(t *testing.T) {
535541 data , err = chain .UpdateGenesisAccounts (accounts , data )
536542 require .NoError (t , err )
537543
538- // TODO: VERIFY
544+ // VERIFY: Check that accounts were added
545+ updatedAppstate := data ["app_state" ].(map [string ]any )
546+ updatedAuth := updatedAppstate ["auth" ].(map [string ]any )
547+ updatedAccounts := updatedAuth ["accounts" ].([]any )
548+
549+ // Verify count increased by 2
550+ require .Equal (t , originalCount + 2 , len (updatedAccounts ))
551+
552+ // Verify the new accounts are present with correct data
553+ lastTwoAccounts := updatedAccounts [len (updatedAccounts )- 2 :]
554+
555+ firstAccount := lastTwoAccounts [0 ].(map [string ]any )
556+ require .Equal (t , "/foobar" , firstAccount ["@type" ])
557+ require .Equal (t , "meow120" , firstAccount ["address" ])
558+ require .Equal (t , "124" , firstAccount ["account_number" ])
559+ require .Equal (t , "0" , firstAccount ["sequence" ])
560+ require .Nil (t , firstAccount ["pub_key" ])
561+
562+ secondAccount := lastTwoAccounts [1 ].(map [string ]any )
563+ require .Equal (t , "/foobar" , secondAccount ["@type" ])
564+ require .Equal (t , "meow120321" , secondAccount ["address" ])
565+ require .Equal (t , "1243" , secondAccount ["account_number" ])
566+ require .Equal (t , "0" , secondAccount ["sequence" ])
567+ require .Nil (t , secondAccount ["pub_key" ])
539568}
540569func TestGenesisAlteration_Balance (t * testing.T ) {
541570 bz , err := os .ReadFile ("internal/testdata/testgenesis.json" )
542571 require .NoError (t , err )
543572 var data map [string ]any
544573 require .NoError (t , json .Unmarshal (bz , & data ))
545574
575+ // Get original balances and supply
576+ appstate := data ["app_state" ].(map [string ]any )
577+ bank := appstate ["bank" ].(map [string ]any )
578+ originalBalances := bank ["balances" ].([]any )
579+ originalSupply := bank ["supply" ].([]any )
580+ originalBalanceCount := len (originalBalances )
581+ originalSupplyCount := len (originalSupply )
582+
546583 accounts := []chain.Balance {
547584 {
548585 Address : "cosmosfoo" ,
@@ -557,5 +594,52 @@ func TestGenesisAlteration_Balance(t *testing.T) {
557594 data , err = chain .UpdateGenesisBalances (accounts , data )
558595 require .NoError (t , err )
559596
560- // TODO: VERIFY
597+ // VERIFY: Check that balances were added
598+ updatedAppstate := data ["app_state" ].(map [string ]any )
599+ updatedBank := updatedAppstate ["bank" ].(map [string ]any )
600+ updatedBalances := updatedBank ["balances" ].([]any )
601+ updatedSupply := updatedBank ["supply" ].([]any )
602+
603+ // Verify balance count increased by 2
604+ require .Equal (t , originalBalanceCount + 2 , len (updatedBalances ))
605+
606+ // Verify the new balances are present with correct data
607+ lastTwoBalances := updatedBalances [len (updatedBalances )- 2 :]
608+
609+ firstBalance := lastTwoBalances [0 ].(map [string ]any )
610+ require .Equal (t , "cosmosfoo" , firstBalance ["address" ])
611+ firstCoins := firstBalance ["coins" ].([]any )
612+ require .Len (t , firstCoins , 1 )
613+ firstCoin := firstCoins [0 ].(map [string ]any )
614+ require .Equal (t , "stake" , firstCoin ["denom" ])
615+ require .Equal (t , "100" , firstCoin ["amount" ])
616+
617+ secondBalance := lastTwoBalances [1 ].(map [string ]any )
618+ require .Equal (t , "cosmosfoobar" , secondBalance ["address" ])
619+ secondCoins := secondBalance ["coins" ].([]any )
620+ require .Len (t , secondCoins , 1 )
621+ secondCoin := secondCoins [0 ].(map [string ]any )
622+ require .Equal (t , "stake" , secondCoin ["denom" ])
623+ require .Equal (t , "1122100" , secondCoin ["amount" ])
624+
625+ // Verify supply was updated correctly - should have added new "stake" denom
626+ require .Equal (t , originalSupplyCount + 1 , len (updatedSupply ), "supply should have one new denomination" )
627+
628+ // Find the new stake supply entry
629+ var stakeSupply * big.Int
630+ found := false
631+ for _ , supplyItem := range updatedSupply {
632+ supply := supplyItem .(map [string ]any )
633+ if supply ["denom" ].(string ) == "stake" {
634+ stakeSupply = new (big.Int )
635+ stakeSupply .SetString (supply ["amount" ].(string ), 10 )
636+ found = true
637+ break
638+ }
639+ }
640+ require .True (t , found , "stake supply should have been added to genesis" )
641+
642+ // Verify the stake supply equals the total of added balances (100 + 1122100 = 1122200)
643+ expectedTotal := big .NewInt (1122200 )
644+ require .Equal (t , expectedTotal .String (), stakeSupply .String ())
561645}
0 commit comments