mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
platformvm/config: preserve nanosecond Duration wire format for v2
v1 encoding/json marshaled time.Duration as an integer count of nanoseconds by default; v2 has no default Duration representation and returns a SemanticError unless told otherwise. The PlatformVM configuration (Network, ExecutionConfig) has been on-disk-stable as integer nanoseconds since launch — keep that wire format by passing jsonv1.FormatDurationAsNano(true) at the Marshal/Unmarshal call sites in GetConfig, GetExecutionConfig, and the corresponding tests that prepare fixtures via json.Marshal.
This commit is contained in:
@@ -5,6 +5,7 @@ package config
|
||||
|
||||
import (
|
||||
"github.com/go-json-experiment/json"
|
||||
jsonv1 "github.com/go-json-experiment/json/v1"
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/constants"
|
||||
@@ -78,5 +79,5 @@ func GetConfig(b []byte) (*Config, error) {
|
||||
return &ec, nil
|
||||
}
|
||||
|
||||
return &ec, json.Unmarshal(b, &ec)
|
||||
return &ec, json.Unmarshal(b, &ec, jsonv1.FormatDurationAsNano(true))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package config
|
||||
|
||||
import (
|
||||
"github.com/go-json-experiment/json"
|
||||
jsonv1 "github.com/go-json-experiment/json/v1"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -119,7 +120,7 @@ func TestConfigUnmarshal(t *testing.T) {
|
||||
verifyInitializedStruct(t, *expected)
|
||||
verifyInitializedStruct(t, expected.Network)
|
||||
|
||||
b, err := json.Marshal(expected)
|
||||
b, err := json.Marshal(expected, jsonv1.FormatDurationAsNano(true))
|
||||
require.NoError(err)
|
||||
|
||||
actual, err := GetConfig(b)
|
||||
|
||||
@@ -5,6 +5,7 @@ package config
|
||||
|
||||
import (
|
||||
"github.com/go-json-experiment/json"
|
||||
jsonv1 "github.com/go-json-experiment/json/v1"
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/constants"
|
||||
@@ -50,5 +51,5 @@ func GetExecutionConfig(b []byte) (*ExecutionConfig, error) {
|
||||
return &ec, nil
|
||||
}
|
||||
|
||||
return &ec, json.Unmarshal(b, &ec)
|
||||
return &ec, json.Unmarshal(b, &ec, jsonv1.FormatDurationAsNano(true))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package config
|
||||
|
||||
import (
|
||||
"github.com/go-json-experiment/json"
|
||||
jsonv1 "github.com/go-json-experiment/json/v1"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -77,7 +78,7 @@ func TestExecutionConfigUnmarshal(t *testing.T) {
|
||||
verifyInitializedStruct(t, *expected)
|
||||
verifyInitializedStruct(t, expected.Network)
|
||||
|
||||
b, err := json.Marshal(expected)
|
||||
b, err := json.Marshal(expected, jsonv1.FormatDurationAsNano(true))
|
||||
require.NoError(err)
|
||||
|
||||
actual, err := GetExecutionConfig(b)
|
||||
|
||||
Reference in New Issue
Block a user