code.vegaprotocol.io/vega@v0.79.0/datanode/entities/reward_test.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package entities_test
    17  
    18  import (
    19  	"testing"
    20  	"time"
    21  
    22  	"code.vegaprotocol.io/vega/datanode/entities"
    23  	eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  	"github.com/stretchr/testify/require"
    27  )
    28  
    29  func TestRewardFromProto(t *testing.T) {
    30  	now := time.Now()
    31  	timestamp := now.Add(-1 * time.Second)
    32  	gameID := "Test"
    33  	pbReward := eventspb.RewardPayoutEvent{
    34  		Party:                "a0b1",
    35  		EpochSeq:             "42",
    36  		Asset:                "c2d3",
    37  		Amount:               "123456789",
    38  		PercentOfTotalReward: "3.14",
    39  		Timestamp:            timestamp.UnixNano(),
    40  		RewardType:           "Some Type",
    41  		GameId:               &gameID,
    42  		LockedUntilEpoch:     "44",
    43  		QuantumAmount:        "292929",
    44  	}
    45  
    46  	vegaTime := entities.NanosToPostgresTimestamp(now.UnixNano())
    47  
    48  	reward, err := entities.RewardFromProto(pbReward, generateTxHash(), vegaTime, 1)
    49  	require.NoError(t, err)
    50  	assert.Equal(t, "a0b1", reward.PartyID.String())
    51  	assert.Equal(t, "c2d3", reward.AssetID.String())
    52  	assert.Equal(t, int64(42), reward.EpochID)
    53  	assert.Equal(t, entities.NanosToPostgresTimestamp(timestamp.UnixNano()), reward.Timestamp)
    54  	assert.InDelta(t, 3.14, reward.PercentOfTotal, 0.001)
    55  	assert.True(t, vegaTime.Equal(reward.VegaTime))
    56  	assert.Equal(t, uint64(1), reward.SeqNum)
    57  }