Skip to content

Commit

Permalink
fix tests, handle when no upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBigBoss committed Jul 29, 2023
1 parent c67b931 commit 624302a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
19 changes: 15 additions & 4 deletions persistence/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ func (p *PostgresContext) InitGenesisParams(params *genesis.Params) error {
return fmt.Errorf("cannot initialize params at height %d", p.Height)
}
_, err := tx.Exec(ctx, types.InsertParams(params, p.Height))
p.SetUpgrade(params.AclOwner, "1.0.0", p.Height)
if err != nil {
return err
}
_, err = tx.Exec(ctx, `
INSERT INTO upgrades (signer, version, height, created) VALUES ($1, $2, $3, $4)
ON CONFLICT (version)
DO UPDATE SET signer=EXCLUDED.signer, version=EXCLUDED.version, height=EXCLUDED.height, created=EXCLUDED.created
`, params.AclOwner, "1.0.0", p.Height, p.Height)
return err
}

Expand Down Expand Up @@ -197,10 +204,14 @@ func (p *PostgresContext) getLatestParamsOrFlagsQuery(tableName string) string {
return fmt.Sprintf("SELECT DISTINCT ON (name) %s FROM %s ORDER BY name ASC,%s.height DESC", fields, tableName, tableName)
}

func (p *PostgresContext) SetUpgrade(signer string, version string, height int64) error {
func (p *PostgresContext) SetUpgrade(signer, version string, height int64) error {
ctx, tx := p.getCtxAndTx()
_, err := tx.Exec(ctx, `
INSERT INTO upgrades(signer, version, height, created) VALUES ($1, $2, $3, $4)
`, signer, version, height, p.Height)
return err
`, signer, version, height, p.Height)
if err != nil {
p.logger.Debug().Err(err).Msg("failed to insert upgrade")
return err
}
return nil
}
3 changes: 3 additions & 0 deletions persistence/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ select signer, version, height, created from upgrades where created = $1

upgrade := new(coreTypes.Upgrade)
if err := row.Scan(&upgrade.Signer, &upgrade.Version, &upgrade.Height, &upgrade.Created); err != nil {
if err == pgx.ErrNoRows {
return nil, nil
}
return nil, err
}

Expand Down
8 changes: 6 additions & 2 deletions persistence/test/benchmark_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ MethodLoop:
arg := method.Type.In(i)
switch arg.Kind() {
case reflect.String:
// String values in modifier functions are usually amounts
v = reflect.ValueOf(getRandomIntString(maxStringAmount))
if methodName == "SetUpgrade" {
v = reflect.ValueOf(fmt.Sprintf("%d.0.0", p.Height+1))
} else {
// String values in modifier functions are usually amounts
v = reflect.ValueOf(getRandomIntString(maxStringAmount))
}
case reflect.Slice:
switch arg.Elem().Kind() {
case reflect.Uint8:
Expand Down
6 changes: 3 additions & 3 deletions persistence/test/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func TestStateHash_DeterministicStateWhenUpdatingAppStake(t *testing.T) {
// logic changes, these hashes will need to be updated based on the test output.
// TODO: Add an explicit updateSnapshots flag to the test to make this more clear.
stateHashes := []string{
"379cb08579d2ddd78c8f9c8deddf65c77a9d3bae81d670bb8cbd3c2c394e4e51",
"d6a2ad957b2cb1f91095dde9ca052f180c79ec853c242a6b4ea3c798e5e1e20f",
"f8ef2678a97a3e6ea4c2bdec172af03def9c596dec0db708bd414b0e0c49c25a",
"4381dbb013b2003963600ba22492c904e22f3dab48c0b75f4ce55d9e7f030b0b",
"156633eda7aabf49764167a80df4818c2521ad266e3647c97e3e076f910e2658",
"cb9825b7a5b434c04ae735f1f731aa9fa288bf392c7a9afcbca172b472998892",
}

stakeAmount := initialStakeAmount
Expand Down
3 changes: 3 additions & 0 deletions persistence/trees/trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ func (t *treeStore) updateFlagsTree(flags []*coreTypes.Flag) error {
}

func (t *treeStore) updateUpgradeTree(upgrade *coreTypes.Upgrade) error {
if upgrade == nil {
return nil
}
upgradeBz, err := codec.GetCodec().Marshal(upgrade)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion utility/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestSession_GetSession_SingleFishermanSingleServicerBaseCase(t *testing.T)
numFishermen := 1
numServicers := 1
// needs to be manually updated if business logic changes
expectedSessionId := "b21c41eceba7d8b338e6a51f2519373042b0b23ec1dfe9967c5819d57c60db17"
expectedSessionId := "d64fa91d59e4fdf89130455ebd88dfced45ff166bc4a53323bdf4dd24c02a5f2"

runtimeCfg, utilityMod, _ := prepareEnvironment(t, 5, numServicers, 1, numFishermen)

Expand Down

0 comments on commit 624302a

Please sign in to comment.