Skip to content

Commit

Permalink
Dedupe construction test constants (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Feb 26, 2024
1 parent 267a4d7 commit e556558
Showing 1 changed file with 21 additions and 32 deletions.
53 changes: 21 additions & 32 deletions service/backend/pchain/construction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/ava-labs/avalanche-rosetta/service/backend/common"
"github.com/ava-labs/avalanche-rosetta/service/backend/pchain/indexer"

pmapper "github.com/ava-labs/avalanche-rosetta/mapper/pchain"
avaconstants "github.com/ava-labs/avalanchego/utils/constants"
avajson "github.com/ava-labs/avalanchego/utils/json"
)
Expand All @@ -48,12 +49,6 @@ var (

avaxAssetID, _ = ids.FromString("U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK")

opTypeInput = "INPUT"
opTypeImport = "IMPORT"
opTypeExport = "EXPORT"
opTypeOutput = "OUTPUT"
opTypeStake = "STAKE"

txFee = 1_000_000

coinID1 = "2ryRVCwNSjEinTViuvDkzX41uQzx3g4babXxZMD46ZV1a9X4Eg:0"
Expand Down Expand Up @@ -113,32 +108,30 @@ func TestConstructionDerive(t *testing.T) {
}

func TestExportTxConstruction(t *testing.T) {
opExportAvax := "EXPORT_AVAX"

exportOperations := []*types.Operation{
{
OperationIdentifier: &types.OperationIdentifier{Index: 0},
RelatedOperations: nil,
Type: opExportAvax,
Type: pmapper.OpExportAvax,
Account: pAccountIdentifier,
Amount: mapper.AtomicAvaxAmount(big.NewInt(-1_000_000_000)),
CoinChange: &types.CoinChange{
CoinIdentifier: &types.CoinIdentifier{Identifier: coinID1},
CoinAction: types.CoinSpent,
},
Metadata: map[string]interface{}{
"type": opTypeInput,
"type": pmapper.OpTypeInput,
"sig_indices": []interface{}{0.0},
"locktime": 0.0,
},
},
{
OperationIdentifier: &types.OperationIdentifier{Index: 1},
Type: opExportAvax,
Type: pmapper.OpExportAvax,
Account: cAccountIdentifier,
Amount: mapper.AtomicAvaxAmount(big.NewInt(999_000_000)),
Metadata: map[string]interface{}{
"type": opTypeExport,
"type": pmapper.OpTypeExport,
"threshold": 1.0,
"locktime": 0.0,
},
Expand All @@ -151,7 +144,7 @@ func TestExportTxConstruction(t *testing.T) {

metadataOptions := map[string]interface{}{
"destination_chain": constants.CChain.String(),
"type": opExportAvax,
"type": pmapper.OpExportAvax,
}

payloadsMetadata := map[string]interface{}{
Expand Down Expand Up @@ -328,32 +321,30 @@ func TestExportTxConstruction(t *testing.T) {
}

func TestImportTxConstruction(t *testing.T) {
opImportAvax := "IMPORT_AVAX"

importOperations := []*types.Operation{
{
OperationIdentifier: &types.OperationIdentifier{Index: 0},
RelatedOperations: nil,
Type: opImportAvax,
Type: pmapper.OpImportAvax,
Account: cAccountIdentifier,
Amount: mapper.AtomicAvaxAmount(big.NewInt(-1_000_000_000)),
CoinChange: &types.CoinChange{
CoinIdentifier: &types.CoinIdentifier{Identifier: coinID1},
CoinAction: types.CoinSpent,
},
Metadata: map[string]interface{}{
"type": opTypeImport,
"type": pmapper.OpTypeImport,
"sig_indices": []interface{}{0.0},
"locktime": 0.0,
},
},
{
OperationIdentifier: &types.OperationIdentifier{Index: 1},
Type: opImportAvax,
Type: pmapper.OpImportAvax,
Account: pAccountIdentifier,
Amount: mapper.AtomicAvaxAmount(big.NewInt(999_000_000)),
Metadata: map[string]interface{}{
"type": opTypeOutput,
"type": pmapper.OpTypeOutput,
"threshold": 1.0,
"locktime": 0.0,
},
Expand All @@ -366,7 +357,7 @@ func TestImportTxConstruction(t *testing.T) {

metadataOptions := map[string]interface{}{
"source_chain": constants.CChain.String(),
"type": opImportAvax,
"type": pmapper.OpImportAvax,
}

payloadsMetadata := map[string]interface{}{
Expand Down Expand Up @@ -542,7 +533,6 @@ func TestImportTxConstruction(t *testing.T) {
}

func TestAddValidatorTxConstruction(t *testing.T) {
opAddValidator := "ADD_VALIDATOR"
startTime := uint64(1659592163)
endTime := startTime + 14*86400
shares := uint32(200000)
Expand All @@ -551,26 +541,26 @@ func TestAddValidatorTxConstruction(t *testing.T) {
{
OperationIdentifier: &types.OperationIdentifier{Index: 0},
RelatedOperations: nil,
Type: opAddValidator,
Type: pmapper.OpAddValidator,
Account: pAccountIdentifier,
Amount: mapper.AtomicAvaxAmount(big.NewInt(-2_000_000_000_000)),
CoinChange: &types.CoinChange{
CoinIdentifier: &types.CoinIdentifier{Identifier: coinID1},
CoinAction: "coin_spent",
},
Metadata: map[string]interface{}{
"type": opTypeInput,
"type": pmapper.OpTypeInput,
"sig_indices": []interface{}{0.0},
"locktime": 0.0,
},
},
{
OperationIdentifier: &types.OperationIdentifier{Index: 1},
Type: opAddValidator,
Type: pmapper.OpAddValidator,
Account: pAccountIdentifier,
Amount: mapper.AtomicAvaxAmount(big.NewInt(2_000_000_000_000)),
Metadata: map[string]interface{}{
"type": opTypeStake,
"type": pmapper.OpTypeStakeOutput,
"locktime": 0.0,
"threshold": 1.0,
// the following are ignored by payloads endpoint but generated by parse
Expand All @@ -591,7 +581,7 @@ func TestAddValidatorTxConstruction(t *testing.T) {
}

metadataOptions := map[string]interface{}{
"type": opAddValidator,
"type": pmapper.OpAddValidator,
"node_id": nodeID,
"start": startTime,
"end": endTime,
Expand Down Expand Up @@ -776,34 +766,33 @@ func TestAddValidatorTxConstruction(t *testing.T) {
}

func TestAddDelegatorTxConstruction(t *testing.T) {
opAddDelegator := "ADD_DELEGATOR"
startTime := uint64(1659592163)
endTime := startTime + 14*86400

operations := []*types.Operation{
{
OperationIdentifier: &types.OperationIdentifier{Index: 0},
RelatedOperations: nil,
Type: opAddDelegator,
Type: pmapper.OpAddDelegator,
Account: pAccountIdentifier,
Amount: mapper.AtomicAvaxAmount(big.NewInt(-25_000_000_000)),
CoinChange: &types.CoinChange{
CoinIdentifier: &types.CoinIdentifier{Identifier: coinID1},
CoinAction: "coin_spent",
},
Metadata: map[string]interface{}{
"type": opTypeInput,
"type": pmapper.OpTypeInput,
"sig_indices": []interface{}{0.0},
"locktime": 0.0,
},
},
{
OperationIdentifier: &types.OperationIdentifier{Index: 1},
Type: opAddDelegator,
Type: pmapper.OpAddDelegator,
Account: pAccountIdentifier,
Amount: mapper.AtomicAvaxAmount(big.NewInt(25_000_000_000)),
Metadata: map[string]interface{}{
"type": opTypeStake,
"type": pmapper.OpTypeStakeOutput,
"locktime": 0.0,
"threshold": 1.0,
// the following are ignored by payloads endpoint but generated by parse
Expand All @@ -823,7 +812,7 @@ func TestAddDelegatorTxConstruction(t *testing.T) {
}

metadataOptions := map[string]interface{}{
"type": opAddDelegator,
"type": pmapper.OpAddDelegator,
"node_id": nodeID,
"start": startTime,
"end": endTime,
Expand Down

0 comments on commit e556558

Please sign in to comment.