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

refactor: update models and tests #78

Merged
merged 3 commits into from
Feb 10, 2020
Merged
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
28 changes: 15 additions & 13 deletions client/blocks_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
package client

type BlockForged struct {
Reward int64 `json:"reward,omitempty"`
Fee int64 `json:"fee,omitempty"`
Total int64 `json:"total,omitempty"`
Reward uint64 `json:"reward,omitempty,string"`
Fee uint64 `json:"fee,omitempty,string"`
Total uint64 `json:"total,omitempty,string"`
Amount uint64 `json:"amount,omitempty,string"`
}

type BlockPayload struct {
Expand All @@ -25,16 +26,17 @@ type BlockGenerator struct {
}

type Block struct {
Id string `json:"id,omitempty"`
Version byte `json:"version,omitempty"`
Height int64 `json:"height,omitempty"`
Previous string `json:"previous,omitempty"`
Forged BlockForged `json:"forged,omitempty"`
Payload BlockPayload `json:"payload,omitempty"`
Generator BlockGenerator `json:"generator,omitempty"`
Signature string `json:"signature,omitempty"`
Transactions byte `json:"transactions,omitempty"`
Timestamp Timestamp `json:"timestamp,omitempty"`
Id string `json:"id,omitempty"`
Version byte `json:"version,omitempty"`
Height int64 `json:"height,omitempty"`
Previous string `json:"previous,omitempty"`
Forged BlockForged `json:"forged,omitempty"`
Payload BlockPayload `json:"payload,omitempty"`
Generator BlockGenerator `json:"generator,omitempty"`
Signature string `json:"signature,omitempty"`
Confirmations uint32 `json:"confirmations,omitempty"`
Transactions byte `json:"transactions,omitempty"`
Timestamp Timestamp `json:"timestamp,omitempty"`
}

type Blocks struct {
Expand Down
74 changes: 46 additions & 28 deletions client/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func TestBlocksService_List(t *testing.T) {
"height": 10,
"previous": "dummy",
"forged": {
"reward": 200000000,
"fee": 0,
"total": 200000000
"reward": "200000000",
"fee": "0",
"total": "200000000",
"amount": "0"
},
"payload": {
"hash": "dummy",
Expand All @@ -54,6 +55,7 @@ func TestBlocksService_List(t *testing.T) {
"publicKey": "dummy"
},
"signature": "dummy",
"confirmations": 0,
"transactions": 0,
"timestamp": {
"epoch": 40678848,
Expand Down Expand Up @@ -89,6 +91,7 @@ func TestBlocksService_List(t *testing.T) {
Reward: 200000000,
Fee: 0,
Total: 200000000,
Amount: 0,
},
Payload: BlockPayload{
Hash: "dummy",
Expand All @@ -99,8 +102,9 @@ func TestBlocksService_List(t *testing.T) {
Address: "dummy",
PublicKey: "dummy",
},
Signature: "dummy",
Transactions: 0,
Signature: "dummy",
Confirmations: 0,
Transactions: 0,
Timestamp: Timestamp{
Epoch: 40678848,
Unix: 1530780048,
Expand All @@ -125,9 +129,10 @@ func TestBlocksService_Get(t *testing.T) {
"height": 10,
"previous": "dummy",
"forged": {
"reward": 200000000,
"fee": 0,
"total": 200000000
"reward": "200000000",
"fee": "0",
"total": "200000000",
"amount": "0"
},
"payload": {
"hash": "dummy",
Expand All @@ -139,6 +144,7 @@ func TestBlocksService_Get(t *testing.T) {
"publicKey": "dummy"
},
"signature": "dummy",
"confirmations": 0,
"transactions": 0,
"timestamp": {
"epoch": 40678848,
Expand All @@ -162,6 +168,7 @@ func TestBlocksService_Get(t *testing.T) {
Reward: 200000000,
Fee: 0,
Total: 200000000,
Amount: 0,
},
Payload: BlockPayload{
Hash: "dummy",
Expand All @@ -172,8 +179,9 @@ func TestBlocksService_Get(t *testing.T) {
Address: "dummy",
PublicKey: "dummy",
},
Signature: "dummy",
Transactions: 0,
Signature: "dummy",
Confirmations: 0,
Transactions: 0,
Timestamp: Timestamp{
Epoch: 40678848,
Unix: 1530780048,
Expand Down Expand Up @@ -207,9 +215,11 @@ func TestBlocksService_Transactions(t *testing.T) {
"id": "dummy",
"blockId": "dummy",
"type": 0,
"amount": 10000000,
"fee": 10000000,
"typeGroup": 1,
"amount": "10000000",
"fee": "10000000",
"sender": "dummy",
"senderPublicKey": "dummy",
"recipient": "dummy",
"signature": "dummy",
"vendorField": "dummy",
Expand All @@ -218,7 +228,8 @@ func TestBlocksService_Transactions(t *testing.T) {
"epoch": 40505460,
"unix": 1530606660,
"human": "2018-07-03T08:31:00Z"
}
},
"nonce": "1"
}
]
}`)
Expand All @@ -240,21 +251,24 @@ func TestBlocksService_Transactions(t *testing.T) {
Last: "/api/blocks/10/transactions?page=1&limit=1",
},
Data: []Transaction{{
Id: "dummy",
BlockId: "dummy",
Type: 0,
Amount: 10000000,
Fee: 10000000,
Sender: "dummy",
Recipient: "dummy",
Signature: "dummy",
VendorField: "dummy",
Confirmations: 10348,
Id: "dummy",
BlockId: "dummy",
Type: 0,
TypeGroup: 1,
Amount: 10000000,
Fee: 10000000,
Sender: "dummy",
SenderPublicKey: "dummy",
Recipient: "dummy",
Signature: "dummy",
VendorField: "dummy",
Confirmations: 10348,
Timestamp: Timestamp{
Epoch: 40505460,
Unix: 1530606660,
Human: "2018-07-03T08:31:00Z",
},
Nonce: 1,
}},
})
}
Expand Down Expand Up @@ -285,9 +299,10 @@ func TestBlocksService_Search(t *testing.T) {
"height": 10,
"previous": "dummy",
"forged": {
"reward": 200000000,
"fee": 0,
"total": 200000000
"reward": "200000000",
"fee": "0",
"total": "200000000",
"amount": "0"
},
"payload": {
"hash": "dummy",
Expand All @@ -299,6 +314,7 @@ func TestBlocksService_Search(t *testing.T) {
"publicKey": "dummy"
},
"signature": "dummy",
"confirmations": 0,
"transactions": 0,
"timestamp": {
"epoch": 40678848,
Expand Down Expand Up @@ -335,6 +351,7 @@ func TestBlocksService_Search(t *testing.T) {
Reward: 200000000,
Fee: 0,
Total: 200000000,
Amount: 0,
},
Payload: BlockPayload{
Hash: "dummy",
Expand All @@ -345,8 +362,9 @@ func TestBlocksService_Search(t *testing.T) {
Address: "dummy",
PublicKey: "dummy",
},
Signature: "dummy",
Transactions: 0,
Signature: "dummy",
Confirmations: 0,
Transactions: 0,
Timestamp: Timestamp{
Epoch: 40678848,
Unix: 1530780048,
Expand Down
16 changes: 11 additions & 5 deletions client/delegates_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
package client

type DelegateBlocks struct {
Produced uint32 `json:"produced,omitempty"`
Missed uint32 `json:"missed,omitempty"`
Last Block `json:"last,omitempty"`
Produced uint32 `json:"produced,omitempty"`
Missed uint32 `json:"missed,omitempty"`
Last Block `json:"last,omitempty"`
}

type DelegateProduction struct {
Approval float64 `json:"approval,omitempty"`
Productivity float64 `json:"productivity,omitempty"`
Approval float64 `json:"approval,omitempty"`
}

type DelegateForged struct {
Fees uint64 `json:"fees,omitempty,string"`
Rewards uint64 `json:"rewards,omitempty,string"`
Total uint64 `json:"total,omitempty,string"`
}

type Delegate struct {
Expand All @@ -26,6 +31,7 @@ type Delegate struct {
Rank byte `json:"rank,omitempty"`
Blocks DelegateBlocks `json:"blocks,omitempty"`
Production DelegateProduction `json:"production,omitempty"`
Forged DelegateForged `json:"forged,omitempty"`
}

type Delegates struct {
Expand Down
44 changes: 32 additions & 12 deletions client/delegates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ func TestDelegatesService_List(t *testing.T) {
}
},
"production": {
"approval": 0.01,
"productivity": 68
"approval": 0.01
},
"forged": {
"fees": "468407250508",
"rewards": "13589400000000",
"total": "14057807250508"
}
}
]
Expand Down Expand Up @@ -95,8 +99,12 @@ func TestDelegatesService_List(t *testing.T) {
},
},
Production: DelegateProduction{
Approval: 0.01,
Productivity: 68,
Approval: 0.01,
},
Forged: DelegateForged{
Fees: 468407250508,
Rewards: 13589400000000,
Total: 14057807250508,
},
}},
})
Expand Down Expand Up @@ -140,8 +148,12 @@ func TestDelegatesService_Get(t *testing.T) {
}
},
"production": {
"approval": 0.01,
"productivity": 68
"approval": 0.01
},
"forged": {
"fees": "468407250508",
"rewards": "13589400000000",
"total": "14057807250508"
}
}
}`)
Expand Down Expand Up @@ -180,8 +192,12 @@ func TestDelegatesService_Get(t *testing.T) {
},
},
Production: DelegateProduction{
Approval: 0.01,
Productivity: 68,
Approval: 0.01,
},
Forged: DelegateForged{
Fees: 468407250508,
Rewards: 13589400000000,
Total: 14057807250508,
},
},
})
Expand Down Expand Up @@ -213,9 +229,10 @@ func TestDelegatesService_Blocks(t *testing.T) {
"height": 10,
"previous": "dummy",
"forged": {
"reward": 200000000,
"fee": 0,
"total": 200000000
"reward": "200000000",
"fee": "0",
"total": "200000000",
"amount": "0"
},
"payload": {
"hash": "dummy",
Expand Down Expand Up @@ -262,6 +279,7 @@ func TestDelegatesService_Blocks(t *testing.T) {
Reward: 200000000,
Fee: 0,
Total: 200000000,
Amount: 0,
},
Payload: BlockPayload{
Hash: "dummy",
Expand Down Expand Up @@ -306,7 +324,8 @@ func TestDelegatesService_Voters(t *testing.T) {
{
"address": "dummy",
"publicKey": "dummy",
"balance": 100000000,
"nonce": "1",
"balance": "100000000",
"isDelegate": false
}
]
Expand All @@ -331,6 +350,7 @@ func TestDelegatesService_Voters(t *testing.T) {
Data: []Wallet{{
Address: "dummy",
PublicKey: "dummy",
Nonce: 1,
Balance: 100000000,
IsDelegate: false,
}},
Expand Down
2 changes: 1 addition & 1 deletion client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *NodeService) Configuration(ctx context.Context) (*GetNodeConfiguration,
// Get the node fee statistics.
func (s *NodeService) Fees(ctx context.Context, days int) (*GetNodeFees, *http.Response, error) {
var responseStruct *GetNodeFees
resp, err := s.client.SendRequest(ctx, "GET", "node/fees", FeesRequest{ days }, nil, &responseStruct)
resp, err := s.client.SendRequest(ctx, "GET", "node/fees", FeesRequest{days}, nil, &responseStruct)

if err != nil {
return nil, resp, err
Expand Down
Loading