From 3b64dffda2745d13e57c01b31c69d79ed63ffe0f Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Tue, 25 Apr 2023 11:57:37 +0300 Subject: [PATCH] [#280] ir: Add fee config tests Signed-off-by: Dmitrii Stepanov --- pkg/innerring/config/fee_test.go | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 pkg/innerring/config/fee_test.go diff --git a/pkg/innerring/config/fee_test.go b/pkg/innerring/config/fee_test.go new file mode 100644 index 000000000..a0c56aac1 --- /dev/null +++ b/pkg/innerring/config/fee_test.go @@ -0,0 +1,68 @@ +package config + +import ( + "strings" + "testing" + + "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" + "github.com/spf13/viper" + "github.com/stretchr/testify/require" +) + +func TestConfig(t *testing.T) { + t.Parallel() + t.Run("all set", func(t *testing.T) { + t.Parallel() + file := strings.NewReader( + ` +fee: + main_chain: 50000000 + side_chain: 200000000 + named_container_register: 2500000000 +`, + ) + v := viper.New() + v.SetConfigType("yaml") + err := v.ReadConfig(file) + require.NoError(t, err, "read config file failed") + + config := NewFeeConfig(v) + require.Equal(t, fixedn.Fixed8(50000000), config.MainChainFee(), "main chain fee invalid") + require.Equal(t, fixedn.Fixed8(200000000), config.SideChainFee(), "side chain fee invalid") + require.Equal(t, fixedn.Fixed8(2500000000), config.NamedContainerRegistrationFee(), "named container register fee invalid") + }) + + t.Run("nothing set", func(t *testing.T) { + t.Parallel() + file := strings.NewReader("") + v := viper.New() + v.SetConfigType("yaml") + err := v.ReadConfig(file) + require.NoError(t, err, "read config file failed") + + config := NewFeeConfig(v) + require.Equal(t, fixedn.Fixed8(0), config.MainChainFee(), "main chain fee invalid") + require.Equal(t, fixedn.Fixed8(0), config.SideChainFee(), "side chain fee invalid") + require.Equal(t, fixedn.Fixed8(0), config.NamedContainerRegistrationFee(), "named container register fee invalid") + }) + + t.Run("partially set", func(t *testing.T) { + t.Parallel() + file := strings.NewReader( + ` +fee: + main_chain: 10 +`, + ) + v := viper.New() + v.SetConfigType("yaml") + err := v.ReadConfig(file) + require.NoError(t, err, "read config file failed") + + config := NewFeeConfig(v) + require.Equal(t, fixedn.Fixed8(10), config.MainChainFee(), "main chain fee invalid") + require.Equal(t, fixedn.Fixed8(0), config.SideChainFee(), "side chain fee invalid") + require.Equal(t, fixedn.Fixed8(0), config.NamedContainerRegistrationFee(), "named container register fee invalid") + }) + +}