Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeph Grunschlag committed Jan 25, 2022
1 parent 2610b8a commit e28e1d0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions idb/postgres/postgres_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1876,3 +1876,28 @@ func TestTransactionsTxnAhead(t *testing.T) {
require.NoError(t, row.Error)
}
}

// Test that if genesis hash is different from what is in db metastate
// indexer does not start.
func TestGenesisHashCheckAtDBStartup(t *testing.T) {
_, connStr, shutdownFunc := pgtest.SetupPostgres(t)
defer shutdownFunc()
genesis := test.MakeGenesis()
db := setupIdbWithConnectionString(
t, connStr, genesis, test.MakeGenesisBlock())
defer db.Close()
genesisHash := crypto.HashObj(genesis)
network, err := db.getMetastate(context.Background(), nil, schema.NetworkMetaStateKey)
assert.NoError(t, err)
networkState, err := encoding.DecodeNetworkState([]byte(network))
assert.NoError(t, err)
assert.Equal(t, genesisHash, networkState.GenesisHash)
// connect with different genesis configs
genesis.Network = "testnest"
// different genesisHash, should fail
idb, _, err := OpenPostgres(connStr, idb.IndexerDbOptions{}, nil)
assert.NoError(t, err)
err = idb.LoadGenesis(genesis)
assert.Error(t, err)
assert.Contains(t, err.Error(), "genesis hash not matching")
}

0 comments on commit e28e1d0

Please sign in to comment.