github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/rewarding/admin_test.go (about) 1 // Copyright (c) 2019 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package rewarding 7 8 import ( 9 "context" 10 "encoding/hex" 11 "math/big" 12 "testing" 13 14 "github.com/stretchr/testify/assert" 15 "github.com/stretchr/testify/require" 16 17 "github.com/iotexproject/iotex-core/action/protocol" 18 "github.com/iotexproject/iotex-core/blockchain/genesis" 19 ) 20 21 func TestAdminPb(t *testing.T) { 22 r := require.New(t) 23 24 // actual data of admin.v1 on mainnet 25 b, err := hex.DecodeString("0a133830303030303030303030303030303030303012173138373530303030303030303030303030303030303030186422143830303030303030303030303030303030303030282430b8443855") 26 r.NoError(err) 27 a := admin{} 28 r.NoError(a.Deserialize(b)) 29 30 g := genesis.Default 31 r.Equal(a.blockReward.String(), g.DardanellesBlockRewardStr) 32 r.Equal(a.epochReward.String(), g.AleutianEpochRewardStr) 33 r.Equal(a.numDelegatesForEpochReward, g.NumDelegatesForEpochReward) 34 r.Equal(a.foundationBonus.String(), g.FoundationBonusStr) 35 r.Equal(a.numDelegatesForFoundationBonus, g.NumDelegatesForFoundationBonus) 36 r.Equal(a.foundationBonusLastEpoch, g.FoundationBonusLastEpoch) 37 r.EqualValues(85, a.productivityThreshold) 38 } 39 40 func TestProtocol_SetEpochReward(t *testing.T) { 41 testProtocol(t, func(t *testing.T, ctx context.Context, sm protocol.StateManager, p *Protocol) { 42 amount, err := p.EpochReward(ctx, sm) 43 require.NoError(t, err) 44 assert.Equal(t, big.NewInt(100), amount) 45 46 require.NoError(t, p.SetReward(ctx, sm, big.NewInt(200), false)) 47 48 amount, err = p.EpochReward(ctx, sm) 49 require.NoError(t, err) 50 assert.Equal(t, big.NewInt(200), amount) 51 52 }, false) 53 }