Merge pull request #439 from nspcc-dev/inspectionFixes

Inspection fixes
This commit is contained in:
Roman Khimov 2019-10-21 14:08:31 +03:00 committed by GitHub
commit 60b2cbb809
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 18 additions and 19 deletions

View file

@ -18,8 +18,8 @@ import (
) )
var ( var (
errNoInput = errors.New("No input file was found, specify an input file with the '--in or -i' 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") 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") errFileExist = errors.New("A file with given smart-contract name already exists")
) )

View file

@ -164,7 +164,7 @@ func TestBinBlockDecodeEncode(t *testing.T) {
"908a398dd65dfd2aad6c06090c5a71d5e5280746577a6ddd5a1f2c1453f71ead": false, "908a398dd65dfd2aad6c06090c5a71d5e5280746577a6ddd5a1f2c1453f71ead": false,
} }
hashes := []string{} var hashes []string
for _, tx := range b.Transactions { for _, tx := range b.Transactions {
switch tx.Type { switch tx.Type {

View file

@ -17,7 +17,7 @@ func TestEncodeDecodeContract(t *testing.T) {
assert.Equal(t, ContractType, tx.Type) assert.Equal(t, ContractType, tx.Type)
assert.IsType(t, tx.Data, &ContractTX{}) assert.IsType(t, tx.Data, &ContractTX{})
assert.Equal(t, 0, int(tx.Version)) 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] input := tx.Inputs[0]

View file

@ -122,15 +122,14 @@ func IsDoubleSpend(s storage.Store, tx *transaction.Transaction) bool {
if r.Err != nil { if r.Err != nil {
return false return false
} }
if unspent == nil {
return true
}
for _, input := range inputs { for _, input := range inputs {
if int(input.PrevIndex) >= len(unspent.states) || unspent.states[input.PrevIndex] == CoinStateSpent { if int(input.PrevIndex) >= len(unspent.states) || unspent.states[input.PrevIndex] == CoinStateSpent {
return true return true
} }
} }
} else {
return true
} }
} }

View file

@ -28,7 +28,7 @@ func TestCreateMultiSigRedeemScript(t *testing.T) {
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
bb := br.ReadBytes() bb := br.ReadBytes()
if err != nil { if br.Err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, validators[i].Bytes(), bb) assert.Equal(t, validators[i].Bytes(), bb)

View file

@ -12,7 +12,7 @@ const (
decimals = 100000000 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. // Fixed8 represents a fixed-point number with precision 10^-8.
type Fixed8 int64 type Fixed8 int64

View file

@ -213,7 +213,7 @@ func handleBreak(c *ishell.Context) {
} }
v := getVMFromContext(c) v := getVMFromContext(c)
if len(c.Args) != 1 { if len(c.Args) != 1 {
c.Err(errors.New("Missing parameter <ip>")) c.Err(errors.New("missing parameter <ip>"))
} }
n, err := strconv.Atoi(c.Args[0]) n, err := strconv.Atoi(c.Args[0])
if err != nil { if err != nil {

View file

@ -87,7 +87,7 @@ func CompileAndSave(src string, o *Options) error {
} }
b, err = Compile(bytes.NewReader(b), o) b, err = Compile(bytes.NewReader(b), o)
if err != nil { 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)) log.Println(hex.EncodeToString(b))

View file

@ -85,7 +85,7 @@ func emitSyscall(w *bytes.Buffer, api string) error {
} }
buf := make([]byte, len(api)+1) buf := make([]byte, len(api)+1)
buf[0] = byte(len(api)) buf[0] = byte(len(api))
copy(buf[1:], []byte(api)) copy(buf[1:], api)
return emit(w, vm.SYSCALL, buf) return emit(w, vm.SYSCALL, buf)
} }

View file

@ -91,7 +91,7 @@ func EmitSyscall(w *bytes.Buffer, api string) error {
} }
buf := make([]byte, len(api)+1) buf := make([]byte, len(api)+1)
buf[0] = byte(len(api)) buf[0] = byte(len(api))
copy(buf[1:], []byte(api)) copy(buf[1:], api)
return Emit(w, SYSCALL, buf) return Emit(w, SYSCALL, buf)
} }

View file

@ -67,7 +67,7 @@ func makeStackItem(v interface{}) StackItem {
case StackItem: case StackItem:
return val return val
case []int: case []int:
a := []StackItem{} var a []StackItem
for _, i := range val { for _, i := range val {
a = append(a, makeStackItem(i)) a = append(a, makeStackItem(i))
} }

View file

@ -131,5 +131,5 @@ var assignTestCases = []testCase{
} }
func TestAssignments(t *testing.T) { func TestAssignments(t *testing.T) {
run_testcases(t, assignTestCases) runTestCases(t, assignTestCases)
} }

View file

@ -189,5 +189,5 @@ var binaryExprTestCases = []testCase{
} }
func TestBinaryExprs(t *testing.T) { func TestBinaryExprs(t *testing.T) {
run_testcases(t, binaryExprTestCases) runTestCases(t, binaryExprTestCases)
} }

View file

@ -21,5 +21,5 @@ var numericTestCases = []testCase{
} }
func TestNumericExprs(t *testing.T) { func TestNumericExprs(t *testing.T) {
run_testcases(t, numericTestCases) runTestCases(t, numericTestCases)
} }

View file

@ -240,5 +240,5 @@ var structTestCases = []testCase{
} }
func TestStructs(t *testing.T) { func TestStructs(t *testing.T) {
run_testcases(t, structTestCases) runTestCases(t, structTestCases)
} }

View file

@ -16,7 +16,7 @@ type testCase struct {
result interface{} result interface{}
} }
func run_testcases(t *testing.T, tcases []testCase) { func runTestCases(t *testing.T, tcases []testCase) {
for _, tcase := range tcases { for _, tcase := range tcases {
t.Run(tcase.name, func(t *testing.T) { eval(t, tcase.src, tcase.result) }) t.Run(tcase.name, func(t *testing.T) { eval(t, tcase.src, tcase.result) })
} }