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

enhancement: Verbose Test Harness #540

Merged
merged 24 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 20 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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ run:
timeout: 5m
tests: false
skip-dirs:
- client/v2/common
- client/v2

linters:
disable-all: true
Expand Down
4 changes: 2 additions & 2 deletions .test-env
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Configs for testing repo download:
SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing"
SDK_TESTING_BRANCH="master"
SDK_TESTING_BRANCH="verbose-harness"
tzaffi marked this conversation as resolved.
Show resolved Hide resolved
SDK_TESTING_HARNESS="test-harness"

INSTALL_ONLY=0

VERBOSE_HARNESS=0
VERBOSE_HARNESS=1
tzaffi marked this conversation as resolved.
Show resolved Hide resolved

# WARNING: If set to 1, new features will be LOST when downloading the test harness.
# REGARDLESS: modified features are ALWAYS overwritten.
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ The Algorand golang SDK provides:
- HTTP clients for the algod (agreement) and kmd (key management) APIs
- Standalone functionality for interacting with the Algorand protocol, including transaction signing, message encoding, etc.

# Documentation
## Documentation

Full documentation is available [on pkg.go.dev](https://pkg.go.dev/github.com/algorand/go-algorand-sdk/v2). You can also self-host the documentation by running `godoc -http=:8099` and visiting `http://localhost:8099/pkg/github.com/algorand/go-algorand-sdk` in your web browser.

Additional developer documentation and examples can be found on [developer.algorand.org](https://developer.algorand.org/docs/sdks/go/)

# Package overview
## Package overview
tzaffi marked this conversation as resolved.
Show resolved Hide resolved

In `client/`, the `kmd` packages provide HTTP clients for the Key Management Daemon. It is responsible for managing spending key material, signing transactions, and managing wallets.
In `client/v2` the `algod` package contains a client for the Algorand protocol daemon HTTP API. You can use it to check the status of the blockchain, read a block, look at transactions, or submit a signed transaction.
Expand All @@ -29,16 +29,16 @@ In `client/v2` the `indexer` package contains a client for the Algorand Indexer

`mnemonic` contains support for turning 32-byte keys into checksummed, human-readable mnemonics (and going from mnemonics back to keys).

# SDK Development
## SDK Development

Run tests with `make docker-test`. To set up the sandbox-based test harness without standing up the go-algorand docker image use `make harness`.

We use golangci-lint to run linters on our codebase. Please run `make lint` before you submit a PR to make sure it conforms to linter standards.

# Quick Start
## Quick Start

To download the SDK, open a terminal and use the `go get` command.

```command
```sh
tzaffi marked this conversation as resolved.
Show resolved Hide resolved
tzaffi marked this conversation as resolved.
Show resolved Hide resolved
tzaffi marked this conversation as resolved.
Show resolved Hide resolved
tzaffi marked this conversation as resolved.
Show resolved Hide resolved
go get -u github.com/algorand/go-algorand-sdk/...
```
12 changes: 12 additions & 0 deletions client/v2/algod/algod.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ func (c *Client) PendingTransactionInformation(txid string) *PendingTransactionI
return &PendingTransactionInformation{c: c, txid: txid}
}

func (c *Client) GetLedgerStateDelta(round uint64) *GetLedgerStateDelta {
return &GetLedgerStateDelta{c: c, round: round}
}

func (c *Client) GetTransactionGroupLedgerStateDeltasForRound(round uint64) *GetTransactionGroupLedgerStateDeltasForRound {
return &GetTransactionGroupLedgerStateDeltasForRound{c: c, round: round}
}

func (c *Client) GetLedgerStateDeltaForTransactionGroup(id string) *GetLedgerStateDeltaForTransactionGroup {
return &GetLedgerStateDeltaForTransactionGroup{c: c, id: id}
}

func (c *Client) GetStateProof(round uint64) *GetStateProof {
return &GetStateProof{c: c, round: round}
}
Expand Down
32 changes: 32 additions & 0 deletions client/v2/algod/getLedgerStateDelta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package algod

import (
"context"
"fmt"

"github.com/algorand/go-algorand-sdk/v2/client/v2/common"
"github.com/algorand/go-algorand-sdk/v2/types"
)

// GetLedgerStateDeltaParams contains all of the query parameters for url serialization.
type GetLedgerStateDeltaParams struct {

// Format configures whether the response object is JSON or MessagePack encoded. If
// not provided, defaults to JSON.
Format string `url:"format,omitempty"`
}

// GetLedgerStateDelta get ledger deltas for a round.
type GetLedgerStateDelta struct {
c *Client

round uint64

p GetLedgerStateDeltaParams
}

// Do performs the HTTP request
func (s *GetLedgerStateDelta) Do(ctx context.Context, headers ...*common.Header) (response types.LedgerStateDelta, err error) {
err = s.c.get(ctx, &response, fmt.Sprintf("/v2/deltas/%s", common.EscapeParams(s.round)...), s.p, headers)
return
}
33 changes: 33 additions & 0 deletions client/v2/algod/getLedgerStateDeltaForTransactionGroup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package algod

import (
"context"
"fmt"

"github.com/algorand/go-algorand-sdk/v2/client/v2/common"
"github.com/algorand/go-algorand-sdk/v2/types"
)

// GetLedgerStateDeltaForTransactionGroupParams contains all of the query parameters for url serialization.
type GetLedgerStateDeltaForTransactionGroupParams struct {

// Format configures whether the response object is JSON or MessagePack encoded. If
// not provided, defaults to JSON.
Format string `url:"format,omitempty"`
}

// GetLedgerStateDeltaForTransactionGroup get a ledger delta for a given
// transaction group.
type GetLedgerStateDeltaForTransactionGroup struct {
c *Client

id string

p GetLedgerStateDeltaForTransactionGroupParams
}

// Do performs the HTTP request
func (s *GetLedgerStateDeltaForTransactionGroup) Do(ctx context.Context, headers ...*common.Header) (response types.LedgerStateDelta, err error) {
err = s.c.get(ctx, &response, fmt.Sprintf("/v2/deltas/txn/group/%s", common.EscapeParams(s.id)...), s.p, headers)
return
}
33 changes: 33 additions & 0 deletions client/v2/algod/getTransactionGroupLedgerStateDeltasForRound.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package algod

import (
"context"
"fmt"

"github.com/algorand/go-algorand-sdk/v2/client/v2/common"
"github.com/algorand/go-algorand-sdk/v2/client/v2/common/models"
)

// GetTransactionGroupLedgerStateDeltasForRoundParams contains all of the query parameters for url serialization.
type GetTransactionGroupLedgerStateDeltasForRoundParams struct {

// Format configures whether the response object is JSON or MessagePack encoded. If
// not provided, defaults to JSON.
Format string `url:"format,omitempty"`
}

// GetTransactionGroupLedgerStateDeltasForRound get ledger deltas for transaction
// groups in a given round.
type GetTransactionGroupLedgerStateDeltasForRound struct {
c *Client

round uint64

p GetTransactionGroupLedgerStateDeltasForRoundParams
}

// Do performs the HTTP request
func (s *GetTransactionGroupLedgerStateDeltasForRound) Do(ctx context.Context, headers ...*common.Header) (response models.TransactionGroupLedgerStateDeltasForRoundResponse, err error) {
err = s.c.get(ctx, &response, fmt.Sprintf("/v2/deltas/%s/txn/group", common.EscapeParams(s.round)...), s.p, headers)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package models
// transaction group
type LedgerStateDeltaForTransactionGroup struct {
// Delta ledger StateDelta object
Delta *map[string]interface{} `json:"delta"`
Delta *map[string]interface{} `json:"Delta"`

// Ids
Ids []string `json:"ids"`
Ids []string `json:"Ids"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package models

// TransactionGroupLedgerStateDeltasForRoundResponse response containing all ledger
// state deltas for transaction groups, with their associated Ids, in a single
// round.
type TransactionGroupLedgerStateDeltasForRoundResponse struct {
// Deltas
Deltas []LedgerStateDeltaForTransactionGroup `json:"Deltas"`
}
30 changes: 30 additions & 0 deletions test/algodclientv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func AlgodClientV2Context(s *godog.Suite) {
s.Step(`^we make a UnsetSyncRound call$`, weMakeAUnsetSyncRoundCall)
s.Step(`^we make a SetBlockTimeStampOffset call against offset (\d+)$`, weMakeASetBlockTimeStampOffsetCallAgainstOffset)
s.Step(`^we make a GetBlockTimeStampOffset call$`, weMakeAGetBlockTimeStampOffsetCall)
s.Step(`^we make a GetLedgerStateDelta call against round (\d+)$`, weMakeAGetLedgerStateDeltaCallAgainstRound)
s.Step(`^we make a LedgerStateDeltaForTransactionGroupResponse call for ID "([^"]*)"$`, weMakeALedgerStateDeltaForTransactionGroupResponseCallForID)
s.Step(`^we make a TransactionGroupLedgerStateDeltaForRoundResponse call for round (\d+)$`, weMakeATransactionGroupLedgerStateDeltaForRoundResponseCallForRound)

s.BeforeScenario(func(interface{}) {
globalErrForExamination = nil
Expand Down Expand Up @@ -364,3 +367,30 @@ func weMakeAGetBlockTimeStampOffsetCall() error {
algodClient.GetBlockTimeStampOffset().Do(context.Background())
return nil
}

func weMakeAGetLedgerStateDeltaCallAgainstRound(round int) error {
algodClient, err := algod.MakeClient(mockServer.URL, "")
if err != nil {
return err
}
algodClient.GetLedgerStateDelta(uint64(round)).Do(context.Background())
return nil
}

func weMakeALedgerStateDeltaForTransactionGroupResponseCallForID(id string) error {
algodClient, err := algod.MakeClient(mockServer.URL, "")
if err != nil {
return err
}
algodClient.GetLedgerStateDeltaForTransactionGroup(id).Do(context.Background())
return nil
}

func weMakeATransactionGroupLedgerStateDeltaForRoundResponseCallForRound(round int) error {
algodClient, err := algod.MakeClient(mockServer.URL, "")
if err != nil {
return err
}
algodClient.GetTransactionGroupLedgerStateDeltasForRound(uint64(round)).Do(context.Background())
return nil
}
9 changes: 9 additions & 0 deletions test/responses_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ func weMakeAnyCallTo(client /* algod/indexer */, endpoint string) (err error) {
case "GetBlockTimeStampOffset":
response, err =
algodC.GetBlockTimeStampOffset().Do(context.Background())
case "GetLedgerStateDelta":
response, err =
algodC.GetLedgerStateDelta(123).Do(context.Background())
case "GetTransactionGroupLedgerStateDeltaForRound":
response, err =
algodC.GetTransactionGroupLedgerStateDeltasForRound(123).Do(context.Background())
case "GetLedgerStateDeltaForTransactionGroup":
response, err =
algodC.GetLedgerStateDeltaForTransactionGroup("someID").Do(context.Background())
case "any":
// This is an error case
// pickup the error as the response
Expand Down
6 changes: 5 additions & 1 deletion test/unit.tags
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
@unit.responses.timestamp
@unit.responses.unlimited_assets
@unit.sourcemap
@unit.statedelta
@unit.stateproof.paths
@unit.stateproof.responses
@unit.sync
@unit.tealsign
@unit.timestamp
@unit.responses.statedelta
@unit.responses.timestamp
@unit.responses.txngroupdeltas
@unit.transactions
@unit.transactions.keyreg
@unit.transactions.payment
@unit.txngroupdeltas