Skip to content

Commit

Permalink
Enhancement: Merge develop to feature/box-storage (#384)
Browse files Browse the repository at this point in the history
* Github-Actions: Adding pr title and label checks (#336)

* Dev Tools: Source map decoder (#335)

* Updated CHANGELOG.md

* AVM:  Consolidate TEAL and AVM versions (#345)

* Testing: Use Dev mode network for cucumber tests (#349)

* AVM: Use avm-abi repo (#352)

* Updated CHANGELOG.md

* Enhancement: Use Sandbox for Testing (#360)

Co-authored-by: Michael Diamant <michaeldiamant@users.noreply.github.com>

* Bug-Fix: passthru verbosity (#371)

* Enhancement: Deprecating use of langspec (#366)

Co-authored-by: Michael Diamant <michaeldiamant@users.noreply.github.com>

* StateProof: State proof support (#374)

* Regenerate client.

* Update txn and block objects, cucumber tests passing.

* Enable cucumber tests.

* Update types/stateproof.go

* Add transactions-root-256

* Remove unused code.

* Remove unused file

* Add txn commitments blockheader fields

* Rename signature, add allocbound definitions

* Add txn commitment to header

* PR comments

* Remove unused file

Co-authored-by: Will Winder <wwinder.unh@gmail.com>

* State Proofs: Use generic type for StateProof txn field. (#378)

* Use generic type for StateProof txn field.

* Add missing type.

* Remove GenericDigest.

* fix type assertion on source map version (#370)

* let the json package figure out how to decode the elements of the incoming map (#380)

* StateProof: State Proof Verification additions (#377)

* Regenerate client.

* Remove unused file

* moved files from stateproof verification repo

* now using updated go-stateproof-verification

* fixed go mod

* moved consts near their usage

* added working state proof verifier test

* added unit test and resources

* now using go 1.15 supported function

* changes to avoid dependency of stateproof verification on SDK

* added needed types to stateproof.go for message hashing

* reverted packages, now using up to date go-stateproof-verification

* CR: renamed verification functions

* hashing sp message is now in crypto

* removed hashing of light block header

* CR: now allocating space upfront in hashing state proof message

* attempting to use embedded files

* CR: using GenericDigest in block.go

* CR: Renamed package to match directory

* Removed go 1.15 from CI

* improved embed usage

* CR: removed stateproof verification logic

* tidied go mod file

Co-authored-by: Will Winder <wwinder.unh@gmail.com>
Co-authored-by: Eric Warehime <eric.warehime@gmail.com>

* State Proofs: added compute leaf function for light block header to sdk (#382)

* added compute leaf function for light block header to sdk

* renamed blockheader256

* changed passed type to pointer

* reverted back to copying

* renamed light block header hash func (#383)

* Enable stpf cucumber unit tests (#386)

Co-authored-by: Jack <87339414+algojack@users.noreply.github.com>
Co-authored-by: Ben Guidarelli <ben.guidarelli@gmail.com>
Co-authored-by: Jack Smith <jack.smith@algorand.com>
Co-authored-by: Michael Diamant <michaeldiamant@users.noreply.github.com>
Co-authored-by: algochoi <86622919+algochoi@users.noreply.github.com>
Co-authored-by: Jason Paulos <jasonpaulos@users.noreply.github.com>
Co-authored-by: Barbara Poon <barbara.poon@algorand.com>
Co-authored-by: Zeph Grunschlag <tzaffi@users.noreply.github.com>
Co-authored-by: Eric Warehime <eric.warehime@gmail.com>
Co-authored-by: Will Winder <wwinder.unh@gmail.com>
Co-authored-by: Almog Tal <107349997+almog-t@users.noreply.github.com>
  • Loading branch information
12 people authored Sep 2, 2022
1 parent 42ba3e3 commit b21b064
Show file tree
Hide file tree
Showing 55 changed files with 799 additions and 1,486 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ workflows:
name: 'test_go_<< matrix.go_version >>'
matrix:
parameters:
go_version: ['1.15', '1.16', '1.17']
go_version: ['1.16', '1.17']

jobs:
test:
Expand Down
14 changes: 14 additions & 0 deletions .test-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Configs for testing repo download:
SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing"
SDK_TESTING_BRANCH="feature/box-storage"
SDK_TESTING_HARNESS="test-harness"

VERBOSE_HARNESS=0

# WARNING: If set to 1, new features will be LOST when downloading the test harness.
# REGARDLESS: modified features are ALWAYS overwritten.
REMOVE_LOCAL_FEATURES=0

# WARNING: Be careful when turning on the next variable.
# In that case you'll need to provide all variables expected by `algorand-sdk-testing`'s `.env`
OVERWRITE_TESTING_ENVIRONMENT=0
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.19.0
## Enhancements
* AVM: Consolidate TEAL and AVM versions ([#345](https://github.com/algorand/go-algorand-sdk/pull/345))
* Testing: Use Dev mode network for cucumber tests ([#349](https://github.com/algorand/go-algorand-sdk/pull/349))
* AVM: Use avm-abi repo ([#352](https://github.com/algorand/go-algorand-sdk/pull/352))

# 1.18.0

## What's Changed
Expand Down
25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SRCPATH := $(shell pwd)
TEST_SOURCES := $(shell cd $(SRCPATH) && go list ./...)
TEST_SOURCES_NO_CUCUMBER := $(shell cd $(SRCPATH) && go list ./... | grep -v test)
UNIT_TAGS := "$(shell awk '{print $2}' test/unit.tags | paste -s -d, -)"
INTEGRATIONS_TAGS := "$(shell awk '{print $2}' test/integration.tags | paste -s -d, -)"
GO_IMAGE := golang:$(subst go,,$(shell go version | cut -d' ' -f 3 | cut -d'.' -f 1,2))-stretch

lint:
golint `go list ./... | grep -v /vendor/`
Expand All @@ -19,13 +22,27 @@ test:

unit:
go test $(TEST_SOURCES_NO_CUCUMBER)
cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags="@unit.offline,@unit.algod,@unit.indexer,@unit.transactions.keyreg,@unit.rekey,@unit.tealsign,@unit.dryrun,@unit.responses,@unit.applications,@unit.applications.boxes,@unit.transactions,@unit.indexer.rekey,@unit.responses.messagepack,@unit.responses.231,@unit.responses.messagepack.231,@unit.responses.genesis,@unit.feetest,@unit.indexer.logs,@unit.abijson,@unit.abijson.byname,@unit.transactions.payment,@unit.atomic_transaction_composer,@unit.responses.unlimited_assets,@unit.indexer.ledger_refactoring,@unit.algod.ledger_refactoring,@unit.dryrun.trace.application,@unit.sourcemap" --test.v .
cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(UNIT_TAGS) --test.v .

integration:
go test $(TEST_SOURCES_NO_CUCUMBER)
cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags="@algod,@assets,@auction,@kmd,@send,@indexer,@rekey_v1,@send.keyregtxn,@dryrun,@compile,@applications.verified,@applications.boxes,@indexer.applications,@indexer.231,@abi,@c2c,@compile.sourcemap" --test.v .
cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags=$(INTEGRATIONS_TAGS) --test.v .

display-all-go-steps:
find test -name "*.go" | xargs grep "github.com/cucumber/godog" 2>/dev/null | cut -d: -f1 | sort | uniq | xargs grep -Eo "Step[(].[^\`]+" | awk '{sub(/:Step\(./,":")} 1' | sed -E 's/", [a-zA-Z0-9]+\)//g'

harness:
./test-harness.sh

docker-gosdk-build:
echo "Building docker image from base $(GO_IMAGE)"
docker build -t go-sdk-testing --build-arg GO_IMAGE="$(GO_IMAGE)" -f test/docker/Dockerfile $(shell pwd)

docker-gosdk-run:
docker ps -a
docker run -it --network host go-sdk-testing:latest

docker-test: harness docker-gosdk-build docker-gosdk-run

docker-test:
./test/docker/run_docker.sh

.PHONY: test fmt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ In `client/v2` the `indexer` package contains a client for the Algorand Indexer

# SDK Development

Run tests with `make docker-test`
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`.

# Quick Start

Expand Down
69 changes: 51 additions & 18 deletions abi/abi.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,66 @@
package abi

import (
"fmt"
"math"

"github.com/algorand/go-algorand/data/abi"
avm_abi "github.com/algorand/avm-abi/abi"
)

type Type = abi.Type
type Type = avm_abi.Type

func TypeOf(str string) (Type, error) {
return abi.TypeOf(str)
return avm_abi.TypeOf(str)
}

// MakeTupleType makes tuple ABI type by taking an array of tuple element types as argument.
func MakeTupleType(argumentTypes []Type) (Type, error) {
if len(argumentTypes) == 0 {
return Type{}, fmt.Errorf("tuple must contain at least one type")
}
return avm_abi.MakeTupleType(argumentTypes)
}

// AnyTransactionType is the ABI argument type string for a nonspecific transaction argument
const AnyTransactionType = avm_abi.AnyTransactionType

// PaymentTransactionType is the ABI argument type string for a payment transaction argument
const PaymentTransactionType = avm_abi.PaymentTransactionType

// KeyRegistrationTransactionType is the ABI argument type string for a key registration transaction
// argument
const KeyRegistrationTransactionType = avm_abi.KeyRegistrationTransactionType

// AssetConfigTransactionType is the ABI argument type string for an asset configuration transaction
// argument
const AssetConfigTransactionType = avm_abi.AssetConfigTransactionType

// AssetTransferTransactionType is the ABI argument type string for an asset transfer transaction
// argument
const AssetTransferTransactionType = avm_abi.AssetTransferTransactionType

if len(argumentTypes) >= math.MaxUint16 {
return Type{}, fmt.Errorf("tuple type child type number larger than maximum uint16 error")
}
// AssetFreezeTransactionType is the ABI argument type string for an asset freeze transaction
// argument
const AssetFreezeTransactionType = avm_abi.AssetFreezeTransactionType

strTuple := "(" + argumentTypes[0].String()
for i := 1; i < len(argumentTypes); i++ {
strTuple += "," + argumentTypes[i].String()
}
strTuple += ")"
// ApplicationCallTransactionType is the ABI argument type string for an application call
// transaction argument
const ApplicationCallTransactionType = avm_abi.ApplicationCallTransactionType

return TypeOf(strTuple)
// IsTransactionType checks if a type string represents a transaction type
// argument, such as "txn", "pay", "keyreg", etc.
func IsTransactionType(typeStr string) bool {
return avm_abi.IsTransactionType(typeStr)
}

// AccountReferenceType is the ABI argument type string for account references
const AccountReferenceType = avm_abi.AccountReferenceType

// AssetReferenceType is the ABI argument type string for asset references
const AssetReferenceType = avm_abi.AssetReferenceType

// ApplicationReferenceType is the ABI argument type string for application references
const ApplicationReferenceType = avm_abi.ApplicationReferenceType

// IsReferenceType checks if a type string represents a reference type argument,
// such as "account", "asset", or "application".
func IsReferenceType(typeStr string) bool {
return avm_abi.IsReferenceType(typeStr)
}

// VoidReturnType is the ABI return type string for a method that does not return any value
const VoidReturnType = avm_abi.VoidReturnType
4 changes: 2 additions & 2 deletions abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/stretchr/testify/require"
)

func TestGoAlgorandImportWorks(t *testing.T) {
func TestImportWorks(t *testing.T) {
// This test is not meant to be exhaustive. It's just a simple test to
// verify importing the ABI package from go-algorand is working
// verify importing the ABI package from avm-abi is working

abiType, err := TypeOf("uint64")
require.NoError(t, err)
Expand Down
123 changes: 9 additions & 114 deletions abi/interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,9 @@ import (
"fmt"
"strings"

"github.com/algorand/go-algorand-sdk/types"
avm_abi "github.com/algorand/avm-abi/abi"
)

// AnyTransactionType is the ABI argument type string for a nonspecific
// transaction argument
const AnyTransactionType = "txn"

var transactionArgTypes = map[string]interface{}{
AnyTransactionType: nil, // denotes a placeholder for any of the size types below
string(types.PaymentTx): nil,
string(types.KeyRegistrationTx): nil,
string(types.AssetConfigTx): nil,
string(types.AssetTransferTx): nil,
string(types.AssetFreezeTx): nil,
string(types.ApplicationCallTx): nil,
}

// IsTransactionType checks if a type string represents a transaction type
// argument, such as "txn", "pay", "keyreg", etc.
func IsTransactionType(typeStr string) bool {
_, ok := transactionArgTypes[typeStr]
return ok
}

// AccountReferenceType is the ABI argument type string for account references
const AccountReferenceType = "account"

// AssetReferenceType is the ABI argument type string for asset references
const AssetReferenceType = "asset"

// ApplicationReferenceType is the ABI argument type string for application
// references
const ApplicationReferenceType = "application"

var referenceArgTypes = map[string]interface{}{
AccountReferenceType: nil,
AssetReferenceType: nil,
ApplicationReferenceType: nil,
}

// IsReferenceType checks if a type string represents a reference type argument,
// such as "account", "asset", or "application".
func IsReferenceType(typeStr string) bool {
_, ok := referenceArgTypes[typeStr]
return ok
}

// Arg represents an ABI Method argument
type Arg struct {
// Optional, user-friendly name for the argument
Expand Down Expand Up @@ -95,10 +51,6 @@ func (a *Arg) GetTypeObject() (Type, error) {
return typeObject, err
}

// VoidReturnType is the ABI return type string for a method that does not have
// a return value
const VoidReturnType = "void"

// Return represents an ABI method return value
type Return struct {
// The type of the return value as a string. See the method GetTypeObject to
Expand Down Expand Up @@ -144,91 +96,34 @@ type Method struct {
Returns Return `json:"returns"`
}

// parseMethodArgs parses the arguments from a method signature string.
// trMethod is the complete method signature and startIdx is the index of the
// opening parenthesis of the arguments list. This function returns a list of
// the argument types from the method signature and the index of the closing
// parenthesis of the arguments list.
func parseMethodArgs(strMethod string, startIdx int) ([]string, int, error) {
// handle no args
if startIdx < len(strMethod)-1 && strMethod[startIdx+1] == ')' {
return []string{}, startIdx + 1, nil
}

var argTypes []string
parenCnt := 1
prevPos := startIdx + 1
closeIdx := -1
for curPos := prevPos; curPos < len(strMethod); curPos++ {
if strMethod[curPos] == '(' {
parenCnt++
} else if strMethod[curPos] == ')' {
parenCnt--
}

if parenCnt < 0 {
return nil, -1, fmt.Errorf("method signature parentheses mismatch")
} else if parenCnt > 1 {
continue
}

if strMethod[curPos] == ',' || parenCnt == 0 {
strArg := strMethod[prevPos:curPos]
argTypes = append(argTypes, strArg)
prevPos = curPos + 1
}

if parenCnt == 0 {
closeIdx = curPos
break
}
}

if closeIdx == -1 {
return nil, -1, fmt.Errorf("method signature parentheses mismatch")
}

return argTypes, closeIdx, nil
}

// MethodFromSignature decoded a method signature string into a Method object.
func MethodFromSignature(methodStr string) (Method, error) {
openIdx := strings.Index(methodStr, "(")
if openIdx == -1 {
return Method{}, fmt.Errorf("method signature is missing an open parenthesis")
}

name := methodStr[:openIdx]
if name == "" {
return Method{}, fmt.Errorf("method must have a non empty name")
}

argTypes, closeIdx, err := parseMethodArgs(methodStr, openIdx)
name, argTypesStr, retTypeStr, err := avm_abi.ParseMethodSignature(methodStr)
if err != nil {
return Method{}, err
}

returnType := Return{Type: methodStr[closeIdx+1:]}
returnType := Return{Type: retTypeStr}
if !returnType.IsVoid() {
// fill type object cache and catch any errors
_, err := returnType.GetTypeObject()
if err != nil {
return Method{}, err
return Method{}, fmt.Errorf("Could not parse method return type: %w", err)
}
}

args := make([]Arg, len(argTypes))
for i, argType := range argTypes {
args[i].Type = argType
args := make([]Arg, len(argTypesStr))
for i, argTypeStr := range argTypesStr {
args[i].Type = argTypeStr

if IsTransactionType(argType) || IsReferenceType(argType) {
if IsTransactionType(argTypeStr) || IsReferenceType(argTypeStr) {
continue
}

// fill type object cache and catch any errors
_, err := args[i].GetTypeObject()
if err != nil {
return Method{}, err
return Method{}, fmt.Errorf("Could not parse argument type at index %d: %w", i, err)
}
}

Expand Down
12 changes: 10 additions & 2 deletions client/v2/algod/algod.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (c *Client) Block(round uint64) *Block {
return &Block{c: c, round: round}
}

func (c *Client) GetProof(round uint64, txid string) *GetProof {
return &GetProof{c: c, round: round, txid: txid}
func (c *Client) GetTransactionProof(round uint64, txid string) *GetTransactionProof {
return &GetTransactionProof{c: c, round: round, txid: txid}
}

func (c *Client) Supply() *Supply {
Expand Down Expand Up @@ -112,6 +112,14 @@ func (c *Client) PendingTransactionInformation(txid string) *PendingTransactionI
return &PendingTransactionInformation{c: c, txid: txid}
}

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

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

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

import (
"context"
"fmt"

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

// GetLightBlockHeaderProof gets a proof for a given light block header inside a
// state proof commitment
type GetLightBlockHeaderProof struct {
c *Client

round uint64
}

// Do performs the HTTP request
func (s *GetLightBlockHeaderProof) Do(ctx context.Context, headers ...*common.Header) (response models.LightBlockHeaderProof, err error) {
err = s.c.get(ctx, &response, fmt.Sprintf("/v2/blocks/%s/lightheader/proof", common.EscapeParams(s.round)...), nil, headers)
return
}
Loading

0 comments on commit b21b064

Please sign in to comment.