Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Remove lots of dead code, restructure storage.
Browse files Browse the repository at this point in the history
Also add staticcheck to makefile.

Signed-off-by: Silas Davis <[email protected]>
  • Loading branch information
Silas Davis committed Jun 20, 2019
1 parent 84df27f commit 1941c69
Show file tree
Hide file tree
Showing 101 changed files with 948 additions and 1,036 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,8 @@ push_ci_image: build_ci_image

.PHONY: ready_for_pull_request
ready_for_pull_request: docs fix

.PHONY: staticcheck
staticcheck:
go get honnef.co/go/tools/cmd/staticcheck
staticcheck ./...
4 changes: 2 additions & 2 deletions acm/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestDecodeConcrete(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, concreteAcc, concreteAccOut)
concreteAccOut, err = Decode([]byte("flungepliffery munknut tolopops"))
_, err = Decode([]byte("flungepliffery munknut tolopops"))
assert.Error(t, err)
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func TestAccountTags(t *testing.T) {
assert.Equal(t, "send | call | createContract | createAccount | bond | name | proposal | input | batch | hasBase | hasRole", str)
str, _ = tagged.Get("Roles")
assert.Equal(t, "frogs;dogs", str)
str, _ = tagged.Get("Code")
tagged.Get("Code")
qry, err := query.New("Code CONTAINS '0116002556001600360006101000A815'")
require.NoError(t, err)
assert.True(t, qry.Matches(tagged))
Expand Down
1 change: 1 addition & 0 deletions acm/acmstate/state_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func TestStateCache_Sync(t *testing.T) {
newAcc := acm.NewAccountFromSecret("newAcc")
// Create account
err := cache.UpdateAccount(newAcc)
require.NoError(t, err)

// Set balance for account
balance := uint64(24)
Expand Down
4 changes: 3 additions & 1 deletion acm/bytecode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestBytecode_MarshalJSON(t *testing.T) {

bytecodeOut := new(Bytecode)
err = json.Unmarshal(bs, bytecodeOut)
require.NoError(t, err)

assert.Equal(t, bytecode, *bytecodeOut)
}
Expand All @@ -41,6 +42,7 @@ func TestBytecode_MarshalText(t *testing.T) {

bytecodeOut := new(Bytecode)
err = bytecodeOut.UnmarshalText(bs)
require.NoError(t, err)

assert.Equal(t, bytecode, *bytecodeOut)
}
Expand Down Expand Up @@ -80,6 +82,6 @@ func TestBytecode_Tokens(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, []string{}, tokens)

tokens, err = Bytecode(bc.MustSplice(asm.PUSH3, 1, 2)).Tokens()
_, err = Bytecode(bc.MustSplice(asm.PUSH3, 1, 2)).Tokens()
assert.Error(t, err, "not enough bytes to push")
}
4 changes: 2 additions & 2 deletions acm/validator/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func TestBucket_AlterPower(t *testing.T) {
require.NoError(t, err)
require.Equal(t, big3.Int64(), flow.Int64())

flow, err = bucket.AlterPower(pubA, new(big.Int).Add(maxTotalVotingPower, big1))
_, err = bucket.AlterPower(pubA, new(big.Int).Add(maxTotalVotingPower, big1))
require.Error(t, err, "should fail as we would breach total power")

flow, err = bucket.AlterPower(pubB, big1)
_, err = bucket.AlterPower(pubB, big1)
require.Error(t, err, "should fail as we would breach total power")

// Drop A and raise B - should now succeed
Expand Down
2 changes: 1 addition & 1 deletion acm/validator/ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestValidatorsRing_AlterPower(t *testing.T) {
vs = Copy(vsBase)
vw = NewRing(vs, 5)
powA, powB, powC = 7000, 23, 310
powerChange, totalFlow, err = alterPowers(t, vw, powA, powB, powC)
_, _, err = alterPowers(t, vw, powA, powB, powC)
require.Error(t, err)

powA, powB, powC = 7000, 23, 309
Expand Down
1 change: 1 addition & 0 deletions binary/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ func TestHexBytes_MarshalText(t *testing.T) {
assert.Equal(t, "\"0102030405\"", string(out))
bs2 := new(HexBytes)
err = json.Unmarshal(out, bs2)
require.NoError(t, err)
assert.Equal(t, bs, *bs2)
}
1 change: 1 addition & 0 deletions binary/word256_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestWord256_MarshalText(t *testing.T) {
assert.Equal(t, "\"0102030405000000000000000000000000000000000000000000000000000000\"", string(out))
bs2 := new(Word256)
err = json.Unmarshal(out, bs2)
require.NoError(t, err)
assert.Equal(t, w, *bs2)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/burrow/commands/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ func Configure(output Output) func(cmd *cli.Cmd) {
output.Fatalf("Could not create remote key client: %v", err)
}
conf.GenesisDoc, err = genesisSpec.GenesisDoc(keyClient, *generateNodeKeys || *pool)
if err != nil {
output.Fatalf("could not realise GenesisSpec: %v", err)
}
}

if err != nil {
output.Fatalf("could not realise GenesisSpec: %v", err)
}
}

if *chainNameOpt != "" {
Expand Down
6 changes: 6 additions & 0 deletions cmd/burrow/commands/examine.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func Examine(output Output) func(cmd *cli.Cmd) {

cmd.Action = func() {
start, end, err := parseRange(*rangeArg)
if err != nil {
output.Fatalf("could not parse range '%s': %v", *rangeArg, err)
}

err = explorer.Blocks(start, end,
func(block *bcm.Block) error {
Expand All @@ -61,6 +64,9 @@ func Examine(output Output) func(cmd *cli.Cmd) {

cmd.Action = func() {
start, end, err := parseRange(*rangeArg)
if err != nil {
output.Fatalf("could not parse range '%s': %v", *rangeArg, err)
}

err = explorer.Blocks(start, end,
func(block *bcm.Block) error {
Expand Down
5 changes: 3 additions & 2 deletions consensus/abci/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ type App struct {
// State
blockchain *bcm.Blockchain
validators Validators
checkTx func(txBytes []byte) types.ResponseCheckTx
deliverTx func(txBytes []byte) types.ResponseCheckTx
mempoolLocker sync.Locker
authorizedPeersProvider PeersFilterProvider
// We need to cache these from BeginBlock for when we need actually need it in Commit
Expand Down Expand Up @@ -125,6 +123,9 @@ func (app *App) InitChain(chain types.RequestInitChain) (respInitChain types.Res
}
for _, v := range chain.Validators {
pk, err := crypto.PublicKeyFromABCIPubKey(v.GetPubKey())
if err != nil {
panic(err)
}
err = app.checkValidatorMatches(currentSet, types.Validator{Address: pk.GetAddress().Bytes(), Power: v.Power})
if err != nil {
panic(err)
Expand Down
12 changes: 6 additions & 6 deletions consensus/tendermint/sign_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@ func (lsi *LastSignedInfo) SignProposal(sign tmCryptoSigner, chainID string, pro
// returns error if HRS regression or no SignBytes. returns true if HRS is unchanged
func (lsi *LastSignedInfo) checkHRS(height int64, round int, step int8) (bool, error) {
if lsi.Height > height {
return false, errors.New("Height regression")
return false, errors.New("height regression")
}

if lsi.Height == height {
if lsi.Round > round {
return false, errors.New("Round regression")
return false, errors.New("round regression")
}

if lsi.Round == round {
if lsi.Step > step {
return false, errors.New("Step regression")
return false, errors.New("step regression")
} else if lsi.Step == step {
if lsi.SignBytes != nil {
if lsi.Signature == nil {
panic("pv: Signature is nil but SignBytes is not!")
}
return true, nil
}
return false, errors.New("No Signature found")
return false, errors.New("no Signature found")
}
}
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func (lsi *LastSignedInfo) signVote(sign tmCryptoSigner, chainID string, vote *t
vote.Timestamp = timestamp
vote.Signature = lsi.Signature
} else {
err = fmt.Errorf("Conflicting data")
err = fmt.Errorf("conflicting data")
}
return err
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func (lsi *LastSignedInfo) signProposal(sign tmCryptoSigner, chainID string, pro
proposal.Timestamp = timestamp
proposal.Signature = lsi.Signature
} else {
err = fmt.Errorf("Conflicting data")
err = fmt.Errorf("conflicting data")
}
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (kern *Kernel) supervise() {
shutdownCh := make(chan os.Signal, 1)
reloadCh := make(chan os.Signal, 1)
syncCh := make(chan os.Signal, 1)
signal.Notify(shutdownCh, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
signal.Notify(shutdownCh, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(reloadCh, syscall.SIGHUP)
signal.Notify(syncCh, syscall.SIGUSR1)
for {
Expand Down
2 changes: 2 additions & 0 deletions crypto/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestAddress_MarshalJSON(t *testing.T) {

addrOut := new(Address)
err = json.Unmarshal(bs, addrOut)
require.NoError(t, err)

assert.Equal(t, addr, *addrOut)
}
Expand All @@ -74,6 +75,7 @@ func TestAddress_MarshalText(t *testing.T) {

addrOut := new(Address)
err = addrOut.UnmarshalText(bs)
require.NoError(t, err)

assert.Equal(t, addr, *addrOut)
}
Expand Down
1 change: 1 addition & 0 deletions crypto/public_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestPublicKeySerialisation(t *testing.T) {
require.NoError(t, err)
var pubOut PublicKey
err = proto.Unmarshal(bs, &pubOut)
require.NoError(t, err)
assert.Equal(t, pub, pubOut)

bs, err = json.Marshal(pub)
Expand Down
20 changes: 2 additions & 18 deletions deploy/compile/compilers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

"github.com/hyperledger/burrow/crypto"
Expand Down Expand Up @@ -156,10 +155,8 @@ func Compile(file string, optimize bool, workDir string, libraries map[string]st
input.Settings.Libraries = make(map[string]map[string]string)
input.Settings.Libraries[""] = make(map[string]string)

if libraries != nil {
for l, a := range libraries {
input.Settings.Libraries[""][l] = "0x" + a
}
for l, a := range libraries {
input.Settings.Libraries[""][l] = "0x" + a
}

command, err := json.Marshal(input)
Expand Down Expand Up @@ -253,16 +250,3 @@ func PrintResponse(resp Response, cli bool, logger *logging.Logger) {
}
}
}

func extractObjectNames(script []byte) ([]string, error) {
regExpression, err := regexp.Compile("(contract|library) (.+?) (is)?(.+?)?({)")
if err != nil {
return nil, err
}
objectNamesList := regExpression.FindAllSubmatch(script, -1)
var objects []string
for _, objectNames := range objectNamesList {
objects = append(objects, string(objectNames[2]))
}
return objects, nil
}
34 changes: 13 additions & 21 deletions deploy/compile/compilers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package compile

import (
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/hyperledger/burrow/logging"
"github.com/stretchr/testify/assert"
)
Expand All @@ -24,10 +27,6 @@ type SolcResponse struct {
Version string `mapstructure:"version" json:"version"` // json encoded
}

func BlankSolcItem() *SolcItem {
return &SolcItem{}
}

func BlankSolcResponse() *SolcResponse {
return &SolcResponse{
Version: "",
Expand All @@ -46,6 +45,7 @@ func TestLocalMulti(t *testing.T) {

warning, responseJSON := extractWarningJSON(strings.TrimSpace(string(actualOutput)))
err = json.Unmarshal([]byte(responseJSON), expectedSolcResponse)
require.NoError(t, err)

respItemArray := make([]ResponseItem, 0)

Expand Down Expand Up @@ -90,6 +90,7 @@ func TestLocalSingle(t *testing.T) {

warning, responseJSON := extractWarningJSON(strings.TrimSpace(string(actualOutput)))
err = json.Unmarshal([]byte(responseJSON), expectedSolcResponse)
require.NoError(t, err)

respItemArray := make([]ResponseItem, 0)

Expand Down Expand Up @@ -122,34 +123,25 @@ func TestLocalSingle(t *testing.T) {
}

func TestFaultyContract(t *testing.T) {
var expectedSolcResponse Response

actualOutput, err := exec.Command("solc", "--combined-json", "bin,abi", "faultyContract.sol").CombinedOutput()
err = json.Unmarshal(actualOutput, expectedSolcResponse)
t.Log(expectedSolcResponse.Error)
resp, err := Compile("faultyContract.sol", false, "", make(map[string]string), logging.NewNoopLogger())
t.Log(resp.Error)
const faultyContractFile = "tests/compilers_fixtures/faultyContract.sol"
actualOutput, err := exec.Command("solc", "--combined-json", "bin,abi", faultyContractFile).CombinedOutput()
require.EqualError(t, err, "exit status 1")
resp, err := Compile(faultyContractFile, false, "", make(map[string]string), logging.NewNoopLogger())
require.NoError(t, err)
if err != nil {
if expectedSolcResponse.Error != resp.Error {
t.Errorf("Expected %v got %v", expectedSolcResponse.Error, resp.Error)
if string(actualOutput) != resp.Error {
t.Errorf("Expected %v got %v", string(actualOutput), resp.Error)
}
}
output := strings.TrimSpace(string(actualOutput))
err = json.Unmarshal([]byte(output), expectedSolcResponse)
fmt.Println(output)
}

func testContractPath() string {
baseDir, _ := os.Getwd()
return filepath.Join(baseDir, "..", "..", "tests", "compilers_fixtures")
}

// The solidity 0.4.21 compiler appends something called auxdata to the end of the bin file (this is visible with
// solc --asm). This is a swarm hash of the metadata, and it's always at the end. This includes the path of the
// solidity source file, so it will differ.
func trimAuxdata(bin string) string {
return bin[:len(bin)-86]
}

func extractWarningJSON(output string) (warning string, json string) {
jsonBeginsCertainly := strings.Index(output, `{"contracts":`)

Expand Down
3 changes: 3 additions & 0 deletions deploy/def/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ func (c *Client) TxInput(inputString, amountString, sequenceString string, allow
var amount uint64
if amountString != "" {
amount, err = c.ParseUint64(amountString)
if err != nil {
return nil, err
}
}
var sequence uint64
sequence, err = c.getSequence(sequenceString, inputAddress, c.MempoolSigning && allowMempoolSigning, logger)
Expand Down
9 changes: 9 additions & 0 deletions deploy/jobs/job_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,29 @@ func doJobs(playbook *def.Playbook, args *def.DeployArgs, client *def.Client, lo
return err
}
job.Result, err = SendJob(job.Send, tx, playbook.Account, client, logger)
if err != nil {
return err
}
case *def.RegisterName:
announce(job.Name, "RegisterName", logger)
txs, err := FormulateRegisterNameJob(job.RegisterName, args, playbook, client, logger)
if err != nil {
return err
}
job.Result, err = RegisterNameJob(job.RegisterName, args, playbook, txs, client, logger)
if err != nil {
return err
}
case *def.Permission:
announce(job.Name, "Permission", logger)
tx, err := FormulatePermissionJob(job.Permission, playbook.Account, client, logger)
if err != nil {
return err
}
job.Result, err = PermissionJob(job.Permission, playbook.Account, tx, client, logger)
if err != nil {
return err
}

// Contracts jobs
case *def.Deploy:
Expand Down
Loading

0 comments on commit 1941c69

Please sign in to comment.