diff --git a/client-sdk/go/modules/rofl/policy.go b/client-sdk/go/modules/rofl/policy.go index 321c01edd8..c7c14cb411 100644 --- a/client-sdk/go/modules/rofl/policy.go +++ b/client-sdk/go/modules/rofl/policy.go @@ -47,6 +47,9 @@ const ( FeePolicyInstancePays FeePolicy = 1 // FeePolicyEndorsingNodePays is a fee policy where the endorsing node pays the gas fees. FeePolicyEndorsingNodePays FeePolicy = 2 + + nameFeePolicyInstancePays = "instance" + nameFeePolicyEndorsingNodePays = "endorsing_node" ) // UnmarshalYAML implements yaml.Unmarshaler. @@ -59,9 +62,9 @@ func (fp *FeePolicy) UnmarshalYAML(value *yaml.Node) error { } switch feePolicyStr { - case "instance": + case nameFeePolicyInstancePays: *fp = FeePolicyInstancePays - case "endorsing_node": + case nameFeePolicyEndorsingNodePays: *fp = FeePolicyEndorsingNodePays default: return fmt.Errorf("unsupported fee policy: '%s'", feePolicyStr) @@ -71,3 +74,15 @@ func (fp *FeePolicy) UnmarshalYAML(value *yaml.Node) error { return fmt.Errorf("unsupported fee policy type") } } + +// MarshalYAML implements yaml.Marshaler. +func (fp FeePolicy) MarshalYAML() (interface{}, error) { + switch fp { + case FeePolicyInstancePays: + return nameFeePolicyInstancePays, nil + case FeePolicyEndorsingNodePays: + return nameFeePolicyEndorsingNodePays, nil + default: + return nil, fmt.Errorf("unsupported fee policy: %d", fp) + } +} diff --git a/client-sdk/go/modules/rofl/policy_test.go b/client-sdk/go/modules/rofl/policy_test.go index 7577db277f..8008be811a 100644 --- a/client-sdk/go/modules/rofl/policy_test.go +++ b/client-sdk/go/modules/rofl/policy_test.go @@ -30,6 +30,13 @@ func TestPolicySerialization(t *testing.T) { if tc.ok { require.NoError(err, "yaml.Unmarshal") require.EqualValues(tc.expected, dec) + + var enc []byte + enc, err = yaml.Marshal(dec) + require.NoError(err, "yaml.Marshal") + err = yaml.Unmarshal(enc, &dec) + require.NoError(err, "yaml.Unmarshal") + require.EqualValues(tc.expected, dec) } else { require.Error(err, "yaml.Unmarshal") }