diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 4cd604e59..be9b1cbd9 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -18,8 +18,8 @@ import ( ) var ( - errNoInput = errors.New("No input file was found, specify an input file with the '--in or -i' flag") - errNoSmartContractName = errors.New("No name was provided, specify the '--name or -n' flag") + errNoInput = errors.New("no input file was found, specify an input file with the '--in or -i' flag") + errNoSmartContractName = errors.New("no name was provided, specify the '--name or -n' flag") errFileExist = errors.New("A file with given smart-contract name already exists") ) diff --git a/pkg/core/block_test.go b/pkg/core/block_test.go index 1c2f5e790..b56a7ec36 100644 --- a/pkg/core/block_test.go +++ b/pkg/core/block_test.go @@ -164,7 +164,7 @@ func TestBinBlockDecodeEncode(t *testing.T) { "908a398dd65dfd2aad6c06090c5a71d5e5280746577a6ddd5a1f2c1453f71ead": false, } - hashes := []string{} + var hashes []string for _, tx := range b.Transactions { switch tx.Type { diff --git a/pkg/core/transaction/contract_test.go b/pkg/core/transaction/contract_test.go index 6d6ed4ef0..28bc42032 100644 --- a/pkg/core/transaction/contract_test.go +++ b/pkg/core/transaction/contract_test.go @@ -17,7 +17,7 @@ func TestEncodeDecodeContract(t *testing.T) { assert.Equal(t, ContractType, tx.Type) assert.IsType(t, tx.Data, &ContractTX{}) assert.Equal(t, 0, int(tx.Version)) - assert.Equal(t, 1, int(len(tx.Inputs))) + assert.Equal(t, 1, len(tx.Inputs)) input := tx.Inputs[0] diff --git a/pkg/core/unspent_coin_state.go b/pkg/core/unspent_coin_state.go index ab9cabfaa..a7b566fd8 100644 --- a/pkg/core/unspent_coin_state.go +++ b/pkg/core/unspent_coin_state.go @@ -122,15 +122,14 @@ func IsDoubleSpend(s storage.Store, tx *transaction.Transaction) bool { if r.Err != nil { return false } - if unspent == nil { - return true - } for _, input := range inputs { if int(input.PrevIndex) >= len(unspent.states) || unspent.states[input.PrevIndex] == CoinStateSpent { return true } } + } else { + return true } } diff --git a/pkg/smartcontract/contract_test.go b/pkg/smartcontract/contract_test.go index 1cca3d229..d011aa1b7 100644 --- a/pkg/smartcontract/contract_test.go +++ b/pkg/smartcontract/contract_test.go @@ -28,7 +28,7 @@ func TestCreateMultiSigRedeemScript(t *testing.T) { for i := 0; i < len(validators); i++ { bb := br.ReadBytes() - if err != nil { + if br.Err != nil { t.Fatal(err) } assert.Equal(t, validators[i].Bytes(), bb) diff --git a/pkg/util/fixed8.go b/pkg/util/fixed8.go index 1364a0601..f28f74e45 100644 --- a/pkg/util/fixed8.go +++ b/pkg/util/fixed8.go @@ -12,7 +12,7 @@ const ( decimals = 100000000 ) -var errInvalidString = errors.New("Fixed8 must satisfy following regex \\d+(\\.\\d{1,8})?") +var errInvalidString = errors.New("fixed8 must satisfy following regex \\d+(\\.\\d{1,8})?") // Fixed8 represents a fixed-point number with precision 10^-8. type Fixed8 int64 diff --git a/pkg/vm/cli/cli.go b/pkg/vm/cli/cli.go index f871db287..d5f4461f4 100644 --- a/pkg/vm/cli/cli.go +++ b/pkg/vm/cli/cli.go @@ -213,7 +213,7 @@ func handleBreak(c *ishell.Context) { } v := getVMFromContext(c) if len(c.Args) != 1 { - c.Err(errors.New("Missing parameter ")) + c.Err(errors.New("missing parameter ")) } n, err := strconv.Atoi(c.Args[0]) if err != nil { diff --git a/pkg/vm/compiler/compiler.go b/pkg/vm/compiler/compiler.go index 94bf31ee8..1bb1cc9b8 100644 --- a/pkg/vm/compiler/compiler.go +++ b/pkg/vm/compiler/compiler.go @@ -87,7 +87,7 @@ func CompileAndSave(src string, o *Options) error { } b, err = Compile(bytes.NewReader(b), o) if err != nil { - return fmt.Errorf("Error while trying to compile smart contract file: %v", err) + return fmt.Errorf("error while trying to compile smart contract file: %v", err) } log.Println(hex.EncodeToString(b)) diff --git a/pkg/vm/compiler/emit.go b/pkg/vm/compiler/emit.go index 584979e5d..92be632f8 100644 --- a/pkg/vm/compiler/emit.go +++ b/pkg/vm/compiler/emit.go @@ -85,7 +85,7 @@ func emitSyscall(w *bytes.Buffer, api string) error { } buf := make([]byte, len(api)+1) buf[0] = byte(len(api)) - copy(buf[1:], []byte(api)) + copy(buf[1:], api) return emit(w, vm.SYSCALL, buf) } diff --git a/pkg/vm/emit.go b/pkg/vm/emit.go index 14556b039..db76fc238 100644 --- a/pkg/vm/emit.go +++ b/pkg/vm/emit.go @@ -91,7 +91,7 @@ func EmitSyscall(w *bytes.Buffer, api string) error { } buf := make([]byte, len(api)+1) buf[0] = byte(len(api)) - copy(buf[1:], []byte(api)) + copy(buf[1:], api) return Emit(w, SYSCALL, buf) } diff --git a/pkg/vm/stack_item.go b/pkg/vm/stack_item.go index 468453d7b..925676a67 100644 --- a/pkg/vm/stack_item.go +++ b/pkg/vm/stack_item.go @@ -67,7 +67,7 @@ func makeStackItem(v interface{}) StackItem { case StackItem: return val case []int: - a := []StackItem{} + var a []StackItem for _, i := range val { a = append(a, makeStackItem(i)) } diff --git a/pkg/vm/tests/assign_test.go b/pkg/vm/tests/assign_test.go index 5c2460d41..7882048ec 100644 --- a/pkg/vm/tests/assign_test.go +++ b/pkg/vm/tests/assign_test.go @@ -131,5 +131,5 @@ var assignTestCases = []testCase{ } func TestAssignments(t *testing.T) { - run_testcases(t, assignTestCases) + runTestCases(t, assignTestCases) } diff --git a/pkg/vm/tests/binary_expr_test.go b/pkg/vm/tests/binary_expr_test.go index fd24c2e37..257132bff 100644 --- a/pkg/vm/tests/binary_expr_test.go +++ b/pkg/vm/tests/binary_expr_test.go @@ -189,5 +189,5 @@ var binaryExprTestCases = []testCase{ } func TestBinaryExprs(t *testing.T) { - run_testcases(t, binaryExprTestCases) + runTestCases(t, binaryExprTestCases) } diff --git a/pkg/vm/tests/numeric_test.go b/pkg/vm/tests/numeric_test.go index 53fc3e722..d2589dbf5 100644 --- a/pkg/vm/tests/numeric_test.go +++ b/pkg/vm/tests/numeric_test.go @@ -21,5 +21,5 @@ var numericTestCases = []testCase{ } func TestNumericExprs(t *testing.T) { - run_testcases(t, numericTestCases) + runTestCases(t, numericTestCases) } diff --git a/pkg/vm/tests/struct_test.go b/pkg/vm/tests/struct_test.go index e3de28f91..d739a935f 100644 --- a/pkg/vm/tests/struct_test.go +++ b/pkg/vm/tests/struct_test.go @@ -240,5 +240,5 @@ var structTestCases = []testCase{ } func TestStructs(t *testing.T) { - run_testcases(t, structTestCases) + runTestCases(t, structTestCases) } diff --git a/pkg/vm/tests/vm_test.go b/pkg/vm/tests/vm_test.go index 885e3ebc6..b91b8bb75 100644 --- a/pkg/vm/tests/vm_test.go +++ b/pkg/vm/tests/vm_test.go @@ -16,7 +16,7 @@ type testCase struct { result interface{} } -func run_testcases(t *testing.T, tcases []testCase) { +func runTestCases(t *testing.T, tcases []testCase) { for _, tcase := range tcases { t.Run(tcase.name, func(t *testing.T) { eval(t, tcase.src, tcase.result) }) }