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

FCT anchors specification #154

Open
wants to merge 15 commits 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
104 changes: 45 additions & 59 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,64 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.12
docker:
- image: circleci/golang:1.14

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
environment:
TEST_RESULTS: /tmp/test-results

working_directory: /go/src/github.com/FactomProject/factom
steps:
- checkout
- run: mkdir -p $TEST_RESULTS

- restore_cache:
keys:
- go-mod-v4-{{ checksum "go.sum" }}

- run: go build

- run:
name: Get Glide
command: |
go get -v github.com/Masterminds/glide
cd $GOPATH/src/github.com/Masterminds/glide
git checkout tags/v0.13.1
go install
# Potentially enable coveralls in the future
# - run:
# name: Get goveralls
# command: |
# go get github.com/mattn/goveralls
- run:
name: Get the dependencies
name: Run unit tests
command: |
glide install
- run:
name: Build and install to verify it builds
command: go install -v
PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
gotestsum --junitfile ${TEST_RESULTS}/gotestsum-report.xml -- $PACKAGE_NAMES

- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"

# Move gopath to tmp so we have test files
- run:
name: Move GOPATH to persist
command: cp -r $GOPATH/ /tmp
- store_artifacts:
path: /tmp/test-results
destination: raw-test-output

- store_test_results:
path: /tmp/test-results

- persist_to_workspace:
root: /tmp
paths: go
gofmt:
docker:
- image: circleci/golang:1.14

test:
working_directory: /tmp # All the binaries are saved here
docker:
- image: circleci/golang:1.12
steps:
- checkout
- run:
name: "Enforce Go Formatted Code"
command: test $(gofmt -l . | wc -l) -eq 0

govet:
docker:
- image: circleci/golang:1.14

steps:
- attach_workspace:
at: /tmp
- checkout
- run:
name: Run unit tests
command: |
export PATH="/tmp/go/bin:$PATH"
export GOPATH=/tmp/go
cd /tmp/go/src/github.com/FactomProject/factom
go test -v ./...
name: "Go vet"
command: go vet ./...

workflows:
version: 2
commit-workflow:
build-workflow:
jobs:
- build:
filters:
tags:
only: /.*/
- test:
filters:
tags:
only: /.*/
requires:
- build
- build
- gofmt
- govet
36 changes: 11 additions & 25 deletions ablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package factom

import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -602,62 +601,49 @@ func (a *AdminAddAuthorityEfficiency) String() string {
return s
}

// GetABlock requests a specific ABlock from the factomd API.
func GetABlock(keymr string) (ablock *ABlock, raw []byte, err error) {
params := keyMRRequest{KeyMR: keymr}
// GetABlock requests a specific ABlock from the factomd API
func GetABlock(keymr string) (ablock *ABlock, err error) {
params := keyMRRequest{KeyMR: keymr, NoRaw: true}
req := NewJSON2Request("admin-block", APICounter(), params)
resp, err := factomdRequest(req)
if err != nil {
return
}
if resp.Error != nil {
return nil, nil, resp.Error
return nil, resp.Error
}

// create a wraper construct for the ECBlock API return
wrap := new(struct {
ABlock *ABlock `json:"ablock"`
RawData string `json:"rawdata"`
ABlock *ABlock `json:"ablock"`
})

err = json.Unmarshal(resp.JSONResult(), wrap)
if err != nil {
return
}

raw, err = hex.DecodeString(wrap.RawData)
if err != nil {
return
}

return wrap.ABlock, raw, nil
return wrap.ABlock, nil
}

// GetABlockByHeight requests an ABlock of a specific height from the factomd
// API.
func GetABlockByHeight(height int64) (ablock *ABlock, raw []byte, err error) {
params := heightRequest{Height: height}
func GetABlockByHeight(height int64) (ablock *ABlock, err error) {
params := heightRequest{Height: height, NoRaw: true}
req := NewJSON2Request("ablock-by-height", APICounter(), params)
resp, err := factomdRequest(req)
if err != nil {
return
}
if resp.Error != nil {
return nil, nil, resp.Error
return nil, resp.Error
}

wrap := new(struct {
ABlock *ABlock `json:"ablock"`
RawData string `json:"rawdata"`
ABlock *ABlock `json:"ablock"`
})
if err = json.Unmarshal(resp.JSONResult(), wrap); err != nil {
return
}

raw, err = hex.DecodeString(wrap.RawData)
if err != nil {
return
}

return wrap.ABlock, raw, nil
return wrap.ABlock, nil
}
6 changes: 2 additions & 4 deletions ablock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ func TestGetABlock(t *testing.T) {

SetFactomdServer(ts.URL[7:])

ab, raw, err := GetABlock("e7eb4bda495dbe7657cae1525b6be78bd2fdbad952ebde506b6a97e1cf8f431e")
ab, err := GetABlock("e7eb4bda495dbe7657cae1525b6be78bd2fdbad952ebde506b6a97e1cf8f431e")
if err != nil {
t.Error(err)
}
t.Log("ABlock:", ab)
t.Log(fmt.Sprintf("Raw: %x\n", raw))
}

func TestGetABlockByHeight(t *testing.T) {
Expand Down Expand Up @@ -120,10 +119,9 @@ func TestGetABlockByHeight(t *testing.T) {

SetFactomdServer(ts.URL[7:])

ab, raw, err := GetABlockByHeight(20000)
ab, err := GetABlockByHeight(20000)
if err != nil {
t.Error(err)
}
t.Log("ABlock:", ab)
t.Log(fmt.Sprintf("Raw: %x\n", raw))
}
Loading