pkg: source formatting

Signed-off-by: Ciro S. Costa <utxobr@protonmail.com>
This commit is contained in:
Ciro S. Costa 2021-06-12 11:42:51 -04:00
parent 3442bea9fd
commit ce6332cc39
10 changed files with 23 additions and 51 deletions

View file

@ -15,5 +15,4 @@ func NewHTTPClient(verbose bool) *http.Client {
}
return client
}

View file

@ -23,7 +23,7 @@ const (
)
const (
// Return Codes
// Return Codes.
LevinOk int32 = 0
LevinErrorConnection int32 = -1
LevinErrorConnectionNotFound int32 = -2
@ -40,7 +40,7 @@ func IsValidReturnCode(c int32) bool {
}
const (
// p2p admin commands
// p2p admin commands.
CommandHandshake uint32 = 1001
CommandTimedSync uint32 = 1002
CommandPing uint32 = 1003

View file

@ -3,17 +3,14 @@ package levin_test
import (
"testing"
"github.com/cirocosta/go-monero/pkg/levin"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/stretchr/testify/assert"
"github.com/cirocosta/go-monero/pkg/levin"
)
func TestLevin(t *testing.T) {
spec.Run(t, "NewHeaderFromBytes", func(t *testing.T, when spec.G, it spec.S) {
it("fails w/ wrong size", func() {
bytes := []byte{
0xff,
@ -115,11 +112,9 @@ func TestLevin(t *testing.T) {
assert.Equal(t, header.Flags, levin.LevinPacketReponse)
assert.Equal(t, header.Version, levin.LevinProtocolVersion)
})
})
spec.Run(t, "NewRequestHeader", func(t *testing.T, when spec.G, it spec.S) {
it("assembles properly w/ ping", func() {
bytes := levin.NewRequestHeader(levin.CommandPing, 1).Bytes()
@ -151,6 +146,5 @@ func TestLevin(t *testing.T) {
0x01, 0x00, 0x00, 0x00, // version
})
})
}, spec.Report(report.Log{}), spec.Parallel(), spec.Random())
}

View file

@ -48,7 +48,6 @@ func ParsePeerList(entry Entry) map[string]*Peer {
addr := adr.Entries()
for _, addrField := range addr {
if addrField.Name != "addr" {
continue
}
@ -73,7 +72,6 @@ func ParsePeerList(entry Entry) map[string]*Peer {
}
if ip != "" && port != 0 {
peer := &Peer{
Ip: ip,
Port: port,
@ -88,12 +86,11 @@ func ParsePeerList(entry Entry) map[string]*Peer {
return peers
}
// TODO less panic'ing
// TODO less panic'ing.
func NewNodeFromEntries(entries Entries) Node {
lpl := Node{}
for _, entry := range entries {
if entry.Name == "node_data" {
for _, field := range entry.Entries() {
switch field.Name {

View file

@ -92,7 +92,6 @@ type PortableStorage struct {
}
func NewPortableStorageFromBytes(bytes []byte) (*PortableStorage, error) {
var (
size = 0
idx = 0
@ -150,7 +149,7 @@ func ReadString(bytes []byte) (int, string) {
}
func ReadObject(bytes []byte) (int, Entries) {
var idx = 0
idx := 0
n, i := ReadVarInt(bytes[idx:])
idx += n

View file

@ -3,17 +3,14 @@ package levin_test
import (
"testing"
"github.com/cirocosta/go-monero/pkg/levin"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/stretchr/testify/assert"
"github.com/cirocosta/go-monero/pkg/levin"
)
func TestPortableStorage(t *testing.T) {
spec.Run(t, "NewPortableStorageFromBytes", func(t *testing.T, when spec.G, it spec.S) {
it("fails w/ wrong sigA", func() {
bytes := []byte{
0xaa, 0xaa, 0xaa, 0xaa,
@ -101,11 +98,9 @@ func TestPortableStorage(t *testing.T) {
},
})
})
}, spec.Report(report.Log{}), spec.Parallel(), spec.Random())
spec.Run(t, "ReadVarIn", func(t *testing.T, when spec.G, it spec.S) {
it("i <= 63", func() {
b := []byte{0x08}
n, v := levin.ReadVarInt(b)
@ -127,11 +122,9 @@ func TestPortableStorage(t *testing.T) {
assert.Equal(t, n, 4)
assert.Equal(t, v, 16384)
})
}, spec.Report(report.Log{}), spec.Parallel(), spec.Random())
spec.Run(t, "VarrIn", func(t *testing.T, when spec.G, it spec.S) {
it("i <= 63", func() {
i := 2 // 0b00000010
@ -163,13 +156,10 @@ func TestPortableStorage(t *testing.T) {
0x02, 0x00, 0x01, 0x00, // (1 << 16) | 2
})
})
}, spec.Report(report.Log{}), spec.Parallel(), spec.Random())
spec.Run(t, "PortableStorage", func(t *testing.T, when spec.G, it spec.S) {
it("bytes", func() {
ps := &levin.PortableStorage{
Entries: []levin.Entry{
{
@ -230,6 +220,5 @@ func TestPortableStorage(t *testing.T) {
}, ps.Bytes())
})
}, spec.Report(report.Log{}), spec.Parallel(), spec.Random())
}

View file

@ -185,7 +185,7 @@ func (c *Client) JsonRPC(ctx context.Context, method string, params interface{},
return nil
}
// submitRequest performs any generic HTTP request to the monero node targetted
// submitRequest performs any generic HTTP request to the monero node targeted
// by this client making no assumptions about a particular endpoint.
//
func (c *Client) submitRequest(req *http.Request, response interface{}) error {

View file

@ -8,18 +8,15 @@ import (
"net/http/httptest"
"testing"
"github.com/cirocosta/go-monero/pkg/rpc"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/cirocosta/go-monero/pkg/rpc"
)
func TestClient(t *testing.T) {
spec.Run(t, "JsonRPC", func(t *testing.T, when spec.G, it spec.S) {
var (
ctx = context.Background()
client *rpc.Client
@ -156,6 +153,5 @@ func TestClient(t *testing.T) {
assert.Contains(t, err.Error(), "foo")
assert.Contains(t, err.Error(), "-1")
})
}, spec.Report(report.Terminal{}), spec.Parallel(), spec.Random())
}

View file

@ -45,7 +45,7 @@ type GetTransactionPoolResult struct {
}
func (c *Client) GetTransactionPool(ctx context.Context) (*GetTransactionPoolResult, error) {
var resp = &GetTransactionPoolResult{}
resp := &GetTransactionPoolResult{}
if err := c.Request(ctx, endpointGetTransactionPool, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
@ -80,9 +80,7 @@ type GetTransactionPoolStatsResult struct {
}
func (c *Client) GetTransactionPoolStats(ctx context.Context) (*GetTransactionPoolStatsResult, error) {
var (
resp = new(GetTransactionPoolStatsResult)
)
resp := new(GetTransactionPoolStatsResult)
if err := c.Request(ctx, endpointGetTransactionPoolStats, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
@ -113,7 +111,7 @@ type GetPeerListResult struct {
}
func (c *Client) GetPeerList(ctx context.Context) (*GetPeerListResult, error) {
var resp = &GetPeerListResult{}
resp := &GetPeerListResult{}
if err := c.Request(ctx, endpointGetPeerList, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
@ -130,7 +128,7 @@ type GetHeightResult struct {
}
func (c *Client) GetHeight(ctx context.Context) (*GetHeightResult, error) {
var resp = &GetHeightResult{}
resp := &GetHeightResult{}
if err := c.Request(ctx, endpointGetHeight, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
@ -150,7 +148,7 @@ type GetNetStatsResult struct {
}
func (c *Client) GetNetStats(ctx context.Context) (*GetNetStatsResult, error) {
var resp = &GetNetStatsResult{}
resp := &GetNetStatsResult{}
if err := c.Request(ctx, endpointGetNetStats, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
@ -249,7 +247,7 @@ type GetTransactionsResultJSONTxn struct {
}
func (c *Client) GetTransactions(ctx context.Context, txns []string) (*GetTransactionsResult, error) {
var resp = &GetTransactionsResult{}
resp := &GetTransactionsResult{}
if err := c.Request(ctx, endpointGetTransactions, map[string]interface{}{
"txs_hashes": txns,

View file

@ -36,7 +36,7 @@ type RPCAccessTrackingResult struct {
}
func (c *Client) RPCAccessTracking(ctx context.Context) (*RPCAccessTrackingResult, error) {
var resp = &RPCAccessTrackingResult{}
resp := &RPCAccessTrackingResult{}
if err := c.JsonRPC(ctx, methodRPCAccessTracking, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
@ -61,7 +61,7 @@ type HardForkInfoResult struct {
}
func (c *Client) HardForkInfo(ctx context.Context) (*HardForkInfoResult, error) {
var resp = &HardForkInfoResult{}
resp := &HardForkInfoResult{}
if err := c.JsonRPC(ctx, methodHardForkInfo, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
@ -81,7 +81,7 @@ type GetBansResult struct {
}
func (c *Client) GetBans(ctx context.Context) (*GetBansResult, error) {
var resp = &GetBansResult{}
resp := &GetBansResult{}
if err := c.JsonRPC(ctx, methodGetBans, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
@ -106,7 +106,7 @@ type GetAlternateChainsResult struct {
}
func (c *Client) GetAlternateChains(ctx context.Context) (*GetAlternateChainsResult, error) {
var resp = &GetAlternateChainsResult{}
resp := &GetAlternateChainsResult{}
if err := c.JsonRPC(ctx, methodGetAlternateChains, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
@ -121,7 +121,7 @@ type GetBlockCountResult struct {
}
func (c *Client) GetBlockCount(ctx context.Context) (*GetBlockCountResult, error) {
var resp = &GetBlockCountResult{}
resp := &GetBlockCountResult{}
if err := c.JsonRPC(ctx, methodGetBlockCount, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
@ -221,7 +221,7 @@ type GetConnectionsResult struct {
}
func (c *Client) GetConnections(ctx context.Context) (*GetConnectionsResult, error) {
var resp = &GetConnectionsResult{}
resp := &GetConnectionsResult{}
if err := c.JsonRPC(ctx, methodGetConnections, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
@ -263,7 +263,7 @@ type GetInfoResult struct {
}
func (c *Client) GetInfo(ctx context.Context) (*GetInfoResult, error) {
var resp = &GetInfoResult{}
resp := &GetInfoResult{}
if err := c.JsonRPC(ctx, methodGetInfo, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
@ -300,7 +300,7 @@ type GetLastBlockHeaderResult struct {
}
func (c *Client) GetLastBlockHeader(ctx context.Context) (*GetLastBlockHeaderResult, error) {
var resp = &GetLastBlockHeaderResult{}
resp := &GetLastBlockHeaderResult{}
if err := c.JsonRPC(ctx, methodGetLastBlockHeader, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
@ -490,7 +490,7 @@ type SyncInfoResult struct {
}
func (c *Client) SyncInfo(ctx context.Context) (*SyncInfoResult, error) {
var resp = new(SyncInfoResult)
resp := new(SyncInfoResult)
if err := c.JsonRPC(ctx, methodSyncInfo, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)