1 2 3 4 5 6 7 8 9 | func TestCreateLoanApplication (t *testing.T) { fmt.Println("Entering TestCreateLoanApplication") attributes := make(map[string][]byte) //Create a custom MockStub that internally uses shim.MockStub stub := shim.NewCustomMockStub("mockStub", new(SampleChaincode), attributes) if stub == nil { t.Fatalf("MockStub creation failed") } } |
1 bash-3.2$ go test 2 can't load package: package .: 3 sample_chaincode.go:1:1:1 expected 'package', found 'EOF' |
1 | package main |
1 ./sample_chaincode_test.go:18: undefined: SampleChaincode |
1 2 | type SampleChaincode struct { } |
1 ./sample_chaincode_test.go:16: cannot use new (SampleChaincode) 2 (type *SampleChaincode) as type shim.Chaincode in argument to 3 shim.NewMockStub: 4 *SampleChaincode does not implement shim.Chaincode 5 (missing Init method) |
1 2 3 4 5 6 7 8 9 10 11 | func (t *SampleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) { return nil, nil } func (t *SampleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) { return nil, nil } func (t *SampleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) { return nil, nil } |
1 bash-3.2$ go test 2 Entering TestCreateLoanApplication 3 2017/02/22 19:10:08 MockStub( mockStub &{} ) 4 PASS |
1 2 3 4 | func CreateLoanApplication(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { fmt.Println("Entering CreateLoanApplication") return nil, nil } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | func TestCreateLoanApplicationValidation(t *testing.T) { fmt.Println("Entering TestCreateLoanApplicationValidation") attributes := make(map[string][]byte) stub := shim.NewCustomMockStub("mockStub", new(SampleChaincode), attributes) if stub == nil { t.Fatalf("MockStub creation failed") } stub.MockTransactionStart("t123") _, err := CreateLoanApplication(stub, []string{}) if err == nil { t.Fatalf("Expected CreateLoanApplication to return validation error") } stub.MockTransactionEnd("t123") } |
1 bash-3.2$ go test 2 Entering TestCreateLoanApplication 3 2017/02/22 22:55:52 MockStub( mockStub &{} ) 4 Entering CreateLoanApplication 5 --- FAIL: TestCreateLoanApplicationValidation (0.00s) 6 sample_chaincode_test.go:35: Expected CreateLoanApplication to return validation error 7 FAIL 8 exit status 1 |
1 2 3 4 | func CreateLoanApplication(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { fmt.Println("Entering CreateLoanApplication") return nil, errors.New(“Expected atleast two arguments for loan application creation”) } |
1 bash-3.2$ go test 2 Entering TestCreateLoanApplication 3 2017/02/22 23:02:52 MockStub( mockStub &{} ) 4 Entering CreateLoanApplication 5 PASS |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | var loanApplicationID = "la1" var loanApplication = `{"id":"` + loanApplicationID + `","propertyId":"prop1","landId":"land1","permitId":"permit1","buyerId":"vojha24","personalInfo":{"firstname":"Varun","lastname":"Ojha","dob":"dob","email":"varun@gmail.com","mobile":"99999999"},"financialInfo":{"monthlySalary":16000,"otherExpenditure":0,"monthlyRent":4150,"monthlyLoanPayment":4000},"status":"Submitted","requestedAmount":40000,"fairMarketValue":58000,"approvedAmount":40000,"reviewedBy":"bond","lastModifiedDate":"21/09/2016 2:30pm"}` func TestCreateLoanApplicationValidation2(t *testing.T) { fmt.Println("Entering TestCreateLoanApplicationValidation2") attributes := make(map[string][]byte) stub := shim.NewCustomMockStub("mockStub", new(SampleChaincode), attributes) if stub == nil { t.Fatalf("MockStub creation failed") } stub.MockTransactionStart("t123") _, err := CreateLoanApplication(stub, []string{loanApplicationID, loanApplication}) if err != nil { t.Fatalf("Expected CreateLoanApplication to succeed") } stub.MockTransactionEnd("t123") } |
1 Entering TestCreateLoanApplicationValidation2 2 2017/02/22 23:09:01 MockStub( mockStub &{} ) 3 Entering CreateLoanApplication 4 --- FAIL: TestCreateLoanApplicationValidation2 (0.00s) 5 sample_chaincode_test.go:55 Expected CreateLoanApplication to succeed 6 FAIL 7 exit status 1 |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |