diff --git a/assets/get.go b/assets/get.go index eb60a6b..a29a82b 100644 --- a/assets/get.go +++ b/assets/get.go @@ -41,8 +41,6 @@ func get(stub *sw.StubWrapper, pvtCollection, key string, committed bool) (*Asse return nil, errors.WrapErrorWithStatus(err, "failed to unmarshal asset from ledger", 500) } - delete(response, "@lastTouchBy") - return &response, nil } @@ -181,7 +179,6 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ return nil, errors.WrapErrorWithStatus(err, "failed to unmarshal asset from ledger", 500) } - delete(response, "@lastTouchBy") keysCheckedInScope := make([]string, 0) for k, v := range response { diff --git a/assets/put.go b/assets/put.go index 7e5cb4f..7282f19 100644 --- a/assets/put.go +++ b/assets/put.go @@ -48,8 +48,6 @@ func (a *Asset) put(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCErr return nil, errors.WrapError(err, "failed to write asset to ledger") } - delete(*a, "@lastTouchBy") - return *a, nil } diff --git a/assets/search.go b/assets/search.go index c9273fc..ffe1e07 100644 --- a/assets/search.go +++ b/assets/search.go @@ -99,8 +99,6 @@ func Search(stub *sw.StubWrapper, request map[string]interface{}, privateCollect data = asset } - delete(data, "@lastTouchBy") - searchResult = append(searchResult, data) } diff --git a/test/assets_get_test.go b/test/assets_get_test.go index 515ce71..5ec10e2 100644 --- a/test/assets_get_test.go +++ b/test/assets_get_test.go @@ -16,12 +16,13 @@ func TestGetAsset(t *testing.T) { // State setup expectedResponse := assets.Asset{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, } stub.MockTransactionStart("setupGetAsset") setupState, _ := json.Marshal(expectedResponse) @@ -92,9 +93,6 @@ func TestGetManyAssets(t *testing.T) { stub.PutState("person:916c708a-1d6c-5c4f-8f12-d9d36f2aad27", setupState) stub.MockTransactionEnd("setupGetManyAssets") - delete(asset1, "@lastTouchBy") - delete(asset2, "@lastTouchBy") - delete(asset3, "@lastTouchBy") expectedResponse := []*assets.Asset{&asset1, &asset2, &asset3} assetKeys := []assets.Key{ @@ -163,7 +161,6 @@ func TestGetCommittedAsset(t *testing.T) { t.FailNow() } - delete(expectedResponse, "@lastTouchBy") if !reflect.DeepEqual(*gotAsset, expectedResponse) { log.Println("these should be deeply equal") log.Println(expectedResponse) @@ -219,18 +216,20 @@ func TestGetRecursive(t *testing.T) { "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", } expectedResponse := map[string]interface{}{ - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "createAsset", - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org2MSP", + "@lastTx": "createAsset", + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", "currentTenant": map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, }, "genres": []interface{}{"biography", "non-fiction"}, "published": "2019-05-06T22:12:41Z", @@ -296,16 +295,18 @@ func TestGetRecursiveWithPvtData(t *testing.T) { "@key": "library:37262f3f-5f08-5649-b488-e5abaad266e1", } expectedResponse := map[string]interface{}{ - "@assetType": "library", - "@key": "library:37262f3f-5f08-5649-b488-e5abaad266e1", - "@lastTx": "createAsset", - "name": "Biblioteca Maria da Silva", + "@assetType": "library", + "@key": "library:37262f3f-5f08-5649-b488-e5abaad266e1", + "@lastTouchBy": "org3MSP", + "@lastTx": "createAsset", + "name": "Biblioteca Maria da Silva", "entranceCode": map[string]interface{}{ - "@assetType": "secret", - "@key": "secret:73a3f9a7-eb91-5f4d-b1bb-c0487e90f40b", - "@lastTx": "createAsset", - "secretName": "testSecret", - "secret": "this is very secret", + "@assetType": "secret", + "@key": "secret:73a3f9a7-eb91-5f4d-b1bb-c0487e90f40b", + "@lastTouchBy": "org2MSP", + "@lastTx": "createAsset", + "secretName": "testSecret", + "secret": "this is very secret", }, } diff --git a/test/assets_put_test.go b/test/assets_put_test.go index 4b00ca7..2415af3 100644 --- a/test/assets_put_test.go +++ b/test/assets_put_test.go @@ -117,7 +117,6 @@ func TestPutAssetWithSubAsset(t *testing.T) { t.FailNow() } - expectedState["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(expectedState, state) { log.Println("these should be deeply equal") log.Println(expectedState) @@ -159,6 +158,7 @@ func TestPutNewAssetRecursive(t *testing.T) { expectedBook := map[string]interface{}{ "@assetType": "book", "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org1MSP", "@lastTx": "", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "title": "Meu Nome é Maria", @@ -166,6 +166,7 @@ func TestPutNewAssetRecursive(t *testing.T) { "currentTenant": map[string]interface{}{ "@assetType": "person", "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", "@lastTx": "", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "name": "Maria", @@ -216,266 +217,111 @@ func TestPutNewAssetRecursive(t *testing.T) { } func TestUpdateRecursive(t *testing.T) { - tests := []struct { - description string - - assetkey string - asset map[string]interface{} - updateReq map[string]interface{} - expectedResponse func(lastUpdated string) map[string]interface{} - expectedState func(lastUpdated string) map[string]interface{} - }{ - { - description: "update recursive book", - - assetkey: "book:a36a2920-c405-51c3-b584-dcd758338cb5", - asset: map[string]interface{}{ - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 1.66, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2019-05-06T22:12:41Z", - }, - updateReq: map[string]interface{}{ - "@assetType": "book", - "author": "Maria Viana", - "title": "Meu Nome é Maria", - "published": "2022-05-06T22:12:41Z", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "id": "31820792048", - "height": 1.88, - }, - }, - expectedResponse: func(lastUpdated string) map[string]interface{} { - publishedTime, _ := time.Parse(time.RFC3339, "2022-05-06T22:12:41Z") - return map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "name": "Maria", - "id": "31820792048", - "height": 1.88, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": publishedTime, - } - }, - expectedState: func(lastUpdated string) map[string]interface{} { - return map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTouchBy": "org1MSP", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2022-05-06T22:12:41Z", - } - }, + stub := mock.NewMockStub("org1MSP", new(testCC)) + + // Create a book + stub.MockTransactionStart("TestPutAsset") + sw := &sw.StubWrapper{ + Stub: stub, + } + book := map[string]interface{}{ + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 1.66, }, - { - description: "update books in library", - - assetkey: "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", - asset: map[string]interface{}{ - "@assetType": "library", - "name": "biographies", - "books": []interface{}{ - map[string]interface{}{ - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 1.66, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2019-05-06T22:12:41Z", - }, - map[string]interface{}{ - "@assetType": "book", - "title": "Meu Nome é João", - "author": "João Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "name": "João", - "id": "42931801159", - "height": 1.90, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2020-06-06T22:12:41Z", - }, - }, - }, - updateReq: map[string]interface{}{ - "@assetType": "library", - "name": "biographies", - "books": []interface{}{ - map[string]interface{}{ // This book will not be updated - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - }, - map[string]interface{}{ // This book will be updated - "@assetType": "book", - "title": "Meu Nome é João", - "author": "João Viana", - "currentTenant": map[string]interface{}{ // This person will be updated - "@assetType": "person", - "id": "42931801159", - "height": 1.92, - }, - "published": "2020-06-10T22:12:41Z", - }, - }, - }, - expectedResponse: func(lastUpdated string) map[string]interface{} { - publishedTimeBook2, _ := time.Parse(time.RFC3339, "2020-06-10T22:12:41Z") - - return map[string]interface{}{ - "@assetType": "library", - "@key": "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", - "@lastTx": "", - "@lastTouchBy": "org1MSP", - "@lastUpdated": lastUpdated, - "name": "biographies", - "books": []interface{}{ - map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "", - "@lastTouchBy": "org1MSP", - "@lastUpdated": lastUpdated, - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "", - "@lastTouchBy": "org1MSP", - "@lastUpdated": lastUpdated, - "name": "Maria", - "id": "31820792048", - "height": 1.66, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2019-05-06T22:12:41Z", - }, - map[string]interface{}{ - "@assetType": "book", - "@key": "book:679f58a4-578f-563c-9c22-3f51b9fab6d5", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "title": "Meu Nome é João", - "author": "João Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:09c4f266-3bac-5d2f-813b-db3c41ab3375", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "name": "João", - "id": "42931801159", - "height": 1.92, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": publishedTimeBook2, - }, - }, - } - }, - expectedState: func(lastUpdated string) map[string]interface{} { - return map[string]interface{}{ - "@assetType": "library", - "@key": "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", - "@lastTouchBy": "org1MSP", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "name": "biographies", - "books": []interface{}{ - map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - }, - map[string]interface{}{ - "@assetType": "book", - "@key": "book:679f58a4-578f-563c-9c22-3f51b9fab6d5", - }, - }, - } - }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": "2019-05-06T22:12:41Z", + } + + var err error + _, err = assets.PutNewRecursive(sw, book) + if err != nil { + log.Println(err) + t.FailNow() + } + stub.MockTransactionEnd("TestPutAsset") + + // Update the book and the tenant + stub.MockTransactionStart("TestUpdateAsset") + book["published"] = "2022-05-06T22:12:41Z" + book["currentTenant"] = map[string]interface{}{ + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 1.88, + } + + putBook, err := assets.UpdateRecursive(sw, book) + if err != nil { + log.Println(err) + t.FailNow() + } + + publishedTime, _ := time.Parse(time.RFC3339, "2022-05-06T22:12:41Z") + lastUpdated, _ := stub.GetTxTimestamp() + expectedBook := map[string]interface{}{ + "@assetType": "book", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), + "name": "Maria", + "id": "31820792048", + "height": 1.88, }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": publishedTime, } - for _, tt := range tests { - t.Run(tt.description, func(t *testing.T) { - stub := mock.NewMockStub("org1MSP", new(testCC)) - sw := &sw.StubWrapper{ - Stub: stub, - } - - // Put asset - stub.MockTransactionStart("TestPutAsset") - var err error - _, err = assets.PutNewRecursive(sw, tt.asset) - if err != nil { - log.Println(err) - t.FailNow() - } - stub.MockTransactionEnd("TestPutAsset") - - // Update asset - stub.MockTransactionStart("TestUpdateAsset") - updateResult, err := assets.UpdateRecursive(sw, tt.updateReq) - if err != nil { - log.Println(err) - t.FailNow() - } - - lastUpdatedTimestamp, _ := stub.GetTxTimestamp() - lastUpdated := lastUpdatedTimestamp.AsTime().Format(time.RFC3339) - if !reflect.DeepEqual(tt.expectedResponse(lastUpdated), updateResult) { - log.Println("these should be deeply equal") - log.Println(tt.expectedResponse(lastUpdated)) - log.Println(updateResult) - t.FailNow() - } - stub.MockTransactionEnd("TestUpdateAsset") - - // Check state - stateJSON := stub.State[tt.assetkey] - var state map[string]interface{} - err = json.Unmarshal(stateJSON, &state) - if err != nil { - log.Println(err) - t.FailNow() - } - - if !reflect.DeepEqual(tt.expectedState(lastUpdated), state) { - log.Println("these should be deeply equal") - log.Println(tt.expectedState(lastUpdated)) - log.Println(state) - t.FailNow() - } - }) + + // Check if the book is updated + if !reflect.DeepEqual(expectedBook, putBook) { + log.Println("these should be deeply equal") + log.Println(expectedBook) + log.Println(putBook) + t.FailNow() + } + + expectedState := map[string]interface{}{ + "@assetType": "book", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": "2022-05-06T22:12:41Z", + } + + stateJSON := stub.State["book:a36a2920-c405-51c3-b584-dcd758338cb5"] + var state map[string]interface{} + err = json.Unmarshal(stateJSON, &state) + if err != nil { + log.Println(err) + t.FailNow() + } + + if !reflect.DeepEqual(expectedState, state) { + log.Println("these should be deeply equal") + log.Println(expectedState) + log.Println(state) + t.FailNow() } } diff --git a/test/tryout_test.go b/test/tryout_test.go index d5a3089..ab32099 100644 --- a/test/tryout_test.go +++ b/test/tryout_test.go @@ -23,12 +23,13 @@ func TestTryout(t *testing.T) { } expectedPerson := []interface{}{ map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, }, } @@ -58,11 +59,12 @@ func TestTryout(t *testing.T) { expectedBook := []interface{}{ map[string]interface{}{ - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "createAsset", - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org2MSP", + "@lastTx": "createAsset", + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", "currentTenant": map[string]interface{}{ "@assetType": "person", "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", @@ -110,12 +112,13 @@ func TestTryout(t *testing.T) { } expectedUpdatePerson := map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "updateAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 1.67, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org2MSP", + "@lastTx": "updateAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 1.67, } err = invokeAndVerify(stub, "updateAsset", reqUpdatePerson, expectedUpdatePerson, 200) diff --git a/test/tx_createAssetType_test.go b/test/tx_createAssetType_test.go index 7d38cd7..781c5c5 100644 --- a/test/tx_createAssetType_test.go +++ b/test/tx_createAssetType_test.go @@ -118,6 +118,7 @@ func TestCreateAssetType(t *testing.T) { lastUpdated, _ := stub.GetTxTimestamp() expectedResponse = map[string]interface{}{ "@key": "magazine:236a29db-f53c-59e1-ac6d-a4f264dbc477", + "@lastTouchBy": "org1MSP", "@lastTx": "createAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "magazine", @@ -160,7 +161,6 @@ func TestCreateAssetType(t *testing.T) { t.FailNow() } - expectedResponse["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(state, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", state) diff --git a/test/tx_createAsset_test.go b/test/tx_createAsset_test.go index 77a873f..bc0bed8 100644 --- a/test/tx_createAsset_test.go +++ b/test/tx_createAsset_test.go @@ -35,6 +35,7 @@ func TestCreateAsset(t *testing.T) { lastUpdated, _ := stub.GetTxTimestamp() expectedResponse := map[string]interface{}{ "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", "@lastTx": "createAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "person", @@ -79,7 +80,6 @@ func TestCreateAsset(t *testing.T) { t.FailNow() } - expectedResponse["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(state, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", state) @@ -135,6 +135,7 @@ func TestCreateAssetGenericAssociation(t *testing.T) { lastUpdated, _ := stub.GetTxTimestamp() expectedResponse := map[string]interface{}{ "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", "@lastTx": "createAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "person", @@ -185,8 +186,6 @@ func TestCreateAssetGenericAssociation(t *testing.T) { t.FailNow() } - expectedResponse["@lastTouchBy"] = "org1MSP" - if !reflect.DeepEqual(state, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", state) diff --git a/test/tx_deleteAsset_test.go b/test/tx_deleteAsset_test.go index 4f5ae2e..7ff2e7b 100644 --- a/test/tx_deleteAsset_test.go +++ b/test/tx_deleteAsset_test.go @@ -62,7 +62,6 @@ func TestDeleteAsset(t *testing.T) { t.FailNow() } - delete(expectedResponse, "@lastTouchBy") if !reflect.DeepEqual(resPayload, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", resPayload) diff --git a/test/tx_readAsset_test.go b/test/tx_readAsset_test.go index 1cbd3ff..304a84e 100644 --- a/test/tx_readAsset_test.go +++ b/test/tx_readAsset_test.go @@ -55,7 +55,6 @@ func TestReadAsset(t *testing.T) { t.FailNow() } - delete(expectedResponse, "@lastTouchBy") if !reflect.DeepEqual(resPayload, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", resPayload) @@ -110,18 +109,20 @@ func TestReadRecursive(t *testing.T) { "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", } expectedResponse := map[string]interface{}{ - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "createAsset", - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org2MSP", + "@lastTx": "createAsset", + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", "currentTenant": map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, }, "genres": []interface{}{"biography", "non-fiction"}, "published": "2019-05-06T22:12:41Z", diff --git a/test/tx_updateAsset_test.go b/test/tx_updateAsset_test.go index 5192956..9787213 100644 --- a/test/tx_updateAsset_test.go +++ b/test/tx_updateAsset_test.go @@ -69,6 +69,7 @@ func TestUpdateAsset(t *testing.T) { expectedPerson := map[string]interface{}{ "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", "@lastTx": "updateAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "person", @@ -92,10 +93,9 @@ func TestUpdateAsset(t *testing.T) { t.FailNow() } - expectedPerson["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(state, expectedPerson) { log.Println("these should be equal") - log.Printf("%#v\n", state) + log.Printf("%#v\n", resPayload) log.Printf("%#v\n", expectedPerson) t.FailNow() } diff --git a/transactions/readAsset.go b/transactions/readAsset.go index 47ec840..23b5eee 100644 --- a/transactions/readAsset.go +++ b/transactions/readAsset.go @@ -51,15 +51,7 @@ var ReadAsset = Transaction{ return nil, errors.WrapErrorWithStatus(err, "failed to serialize asset", 500) } } else { - var asset *assets.Asset - asset, err = key.Get(stub) - if err != nil { - return nil, errors.WrapError(err, "failed to get asset state") - } - - delete(*asset, "@lastTouchBy") - - assetJSON, err = json.Marshal(asset) + assetJSON, err = key.GetBytes(stub) if err != nil { return nil, errors.WrapError(err, "failed to get asset state") }