Skip to content

Commit

Permalink
fix pointers in err string (ava-labs#1016)
Browse files Browse the repository at this point in the history
* fix pointers in err string

* use ptrToString in description
  • Loading branch information
ceyonur authored Dec 4, 2023
1 parent 2cabeee commit 7a6bcad
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The Subnet EVM runs in a separate process from the main AvalancheGo process and
[v0.5.0] AvalancheGo@v1.10.0 (Protocol Version: 25)
[v0.5.1] AvalancheGo@v1.10.1-v1.10.4 (Protocol Version: 26)
[v0.5.2] AvalancheGo@v1.10.1-v1.10.4 (Protocol Version: 26)
[v0.5.3] AvalancheGo@v1.10.5-v1.10.6 (Protocol Version: 27)
[v0.5.3] AvalancheGo@v1.10.5-v1.10.8 (Protocol Version: 27)
[v0.5.4] AvalancheGo@v1.10.9-v1.10.12 (Protocol Version: 28)
[v0.5.5] AvalancheGo@v1.10.9-v1.10.12 (Protocol Version: 28)
[v0.5.6] AvalancheGo@v1.10.9-v1.10.12 (Protocol Version: 28)
Expand Down
21 changes: 11 additions & 10 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,9 @@ func (c *ChainConfig) Description() string {
banner += fmt.Sprintf(" - Muir Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/muir-glacier.md)\n", c.MuirGlacierBlock)
}
banner += "Mandatory Upgrades:\n"
if c.SubnetEVMTimestamp != nil {
banner += fmt.Sprintf(" - SubnetEVM Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0)\n", *c.SubnetEVMTimestamp)
}
if c.DUpgradeTimestamp != nil {
banner += fmt.Sprintf(" - DUpgrade Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", *c.DUpgradeTimestamp)
}
if c.CancunTime != nil {
banner += fmt.Sprintf(" - Cancun Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", *c.CancunTime)
}
banner += fmt.Sprintf(" - SubnetEVM Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0)\n", ptrToString(c.SubnetEVMTimestamp))
banner += fmt.Sprintf(" - DUpgrade Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", ptrToString(c.DUpgradeTimestamp))
banner += fmt.Sprintf(" - Cancun Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", ptrToString(c.CancunTime))
banner += "\n"

// Add Subnet-EVM custom fields
Expand Down Expand Up @@ -700,7 +694,14 @@ func (err *ConfigCompatError) Error() string {
if err.StoredBlock != nil {
return fmt.Sprintf("mismatching %s in database (have block %d, want block %d, rewindto block %d)", err.What, err.StoredBlock, err.NewBlock, err.RewindToBlock)
}
return fmt.Sprintf("mismatching %s in database (have timestamp %d, want timestamp %d, rewindto timestamp %d)", err.What, err.StoredTime, err.NewTime, err.RewindToTime)
return fmt.Sprintf("mismatching %s in database (have timestamp %s, want timestamp %s, rewindto timestamp %d)", err.What, ptrToString(err.StoredTime), ptrToString(err.NewTime), err.RewindToTime)
}

func ptrToString(val *uint64) string {
if val == nil {
return "nil"
}
return fmt.Sprintf("%d", *val)
}

// Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions
Expand Down
16 changes: 16 additions & 0 deletions params/precompile_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) {
},
},
},
"retroactively enabling upgrades is not allowed": {
expectedErrorString: "cannot retroactively enable PrecompileUpgrade[1] in database (have timestamp nil, want timestamp 5, rewindto timestamp 4)",
startTimestamps: []uint64{6},
configs: []*UpgradeConfig{
{
PrecompileUpgrades: []PrecompileUpgrade{
{
Config: txallowlist.NewDisableConfig(utils.NewUint64(5)),
},
{
Config: txallowlist.NewConfig(utils.NewUint64(6), admins, nil, nil),
},
},
},
},
},
}

for name, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion params/state_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestCheckCompatibleStateUpgrades(t *testing.T) {
},
},
"retroactively enabling upgrades is not allowed": {
expectedErrorString: "cannot retroactively enable StateUpgrade",
expectedErrorString: "cannot retroactively enable StateUpgrade[0] in database (have timestamp nil, want timestamp 5, rewindto timestamp 4)",
startTimestamps: []uint64{6},
configs: []*UpgradeConfig{
{
Expand Down

0 comments on commit 7a6bcad

Please sign in to comment.