Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix: get_producer type add & test #198

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package eos
import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"testing"

"github.com/eoscanada/eos-go/ecc"
mockserver "github.com/eoscanada/eos-go/testdata/mock_server"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -130,6 +132,66 @@ func TestAPIGetCurrencyStats(t *testing.T) {
assert.JSONEq(t, string(expectedJSON), string(actualJSON))
}

func TestAPIGetProducers(t *testing.T) {
producers, err := api.GetProducers(context.Background())
assert.NoError(t, err)

type tempProducers struct {
Owner Name `json:"owner"`
TotalVotes Float64 `json:"total_votes,string"`
ProducerKey ecc.PublicKey `json:"producer_key"`
IsActive int `json:"is_active"`
URL string `json:"url"`
UnpaidBlocks int `json:"unpaid_blocks"`
LastClaimTime BlockTimestamp `json:"last_claim_time"`
Location int `json:"location"`
ProducerAuthority *BlockSigningAuthority `json:"producer_authority,omitempty"` // added since EOSIO/Leap v2.0
}

type tempProducerResp struct {
Producers []tempProducers `json:"rows"`
TotalProducerVoteWeight Float64 `json:"total_producer_vote_weight,string"`
More Name `json:"more"`
}

parsedResp := tempProducerResp{
Producers: []tempProducers{},
TotalProducerVoteWeight: producers.TotalProducerVoteWeight,
More: producers.More,
}

for _, item := range producers.Producers {
newItem := tempProducers{
item.Owner,
item.TotalVotes,
item.ProducerKey,
1,
item.URL,
item.UnpaidBlocks,
item.LastClaimTime,
item.Location,
item.ProducerAuthority,
}

if item.IsActive {
newItem.IsActive = 1
} else {
newItem.IsActive = 0
}

parsedResp.Producers = append(parsedResp.Producers, newItem)
}

actualJSON, err := json.Marshal(parsedResp)
assert.NoError(t, err)

expectedJSON := mockserver.OpenFile(".", "chain_get_producers.json")

assert.JSONEq(t, string(expectedJSON), string(actualJSON))

fmt.Println("totalvote: ", producers.TotalProducerVoteWeight)
}

func TestMain(m *testing.M) {
setUp()
code := m.Run()
Expand Down
17 changes: 9 additions & 8 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,15 @@ type Global struct {
}

type Producer struct {
Owner Name `json:"owner"`
TotalVotes Float64 `json:"total_votes,string"`
ProducerKey ecc.PublicKey `json:"producer_key"`
IsActive Bool `json:"is_active"`
URL string `json:"url"`
UnpaidBlocks int `json:"unpaid_blocks"`
LastClaimTime JSONTime `json:"last_claim_time"`
Location int `json:"location"`
Owner Name `json:"owner"`
TotalVotes Float64 `json:"total_votes,string"`
ProducerKey ecc.PublicKey `json:"producer_key"`
IsActive Bool `json:"is_active"`
URL string `json:"url"`
UnpaidBlocks int `json:"unpaid_blocks"`
LastClaimTime BlockTimestamp `json:"last_claim_time"`
Location int `json:"location"`
ProducerAuthority *BlockSigningAuthority `json:"producer_authority,omitempty"` // added since EOSIO/Leap v2.0
}

type ProducersResp struct {
Expand Down
Loading