Skip to content

Commit

Permalink
Merge pull request #4 from angeldraghici/main
Browse files Browse the repository at this point in the history
Fixes for AttribRequests
  • Loading branch information
joyride9999 authored Jan 3, 2023
2 parents b34aae8 + bd246ef commit 2e683eb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func BuildNymRequest(submitterDid string, targetDid string, targetVerkey string,
}

// BuildAttribRequest Builds an ATTRIB request. Request to add attribute to a NYM record.
func BuildAttribRequest(submitterDid string, targetDid, hash string, raw string, encrypted string) (string, error) {
func BuildAttribRequest(submitterDid string, targetDid, raw string, hash string, encrypted string) (string, error) {

upSubmitterDid := unsafe.Pointer(C.CString(submitterDid))
defer C.free(upSubmitterDid)
Expand All @@ -137,7 +137,7 @@ func BuildAttribRequest(submitterDid string, targetDid, hash string, raw string,
upEncData := unsafe.Pointer(GetOptionalValue(encrypted))
defer C.free(upEncData)

channel := ledger.BuildAttribRequest(upSubmitterDid, upTargetDid, upHash, upRawData, upEncData)
channel := ledger.BuildAttribRequest(upSubmitterDid, upTargetDid, upRawData, upHash, upEncData)
result := <-channel
if result.Error != nil {
return "", result.Error
Expand Down
2 changes: 1 addition & 1 deletion ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ func BuildNymRequest(submitterDid, targetDid, verkey, alias, role unsafe.Pointer
}

// BuildAttribRequest Builds an ATTRIB request. Request to add attribute to a NYM record.
func BuildAttribRequest(submitterDid, targetDid, hash, raw, enc unsafe.Pointer) chan indyUtils.IndyResult {
func BuildAttribRequest(submitterDid, targetDid, raw, hash, enc unsafe.Pointer) chan indyUtils.IndyResult {

// Prepare the call parameters
handle, future := indyUtils.NewFutureCommand()
Expand Down
24 changes: 12 additions & 12 deletions ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func TestSubmitRequest(t *testing.T) {
return
}

getAttribRequest, errAttrib := prepareGetAttribReq(poolHandle, walletHandle, trusteeDid, did, "", `{"test":"name"}`, ""); if errAttrib != nil {
getAttribRequest, errAttrib := prepareGetAttribReq(poolHandle, walletHandle, trusteeDid, did, `{"test":"name"}`, "", ""); if errAttrib != nil {
t.Errorf("prepareGetAttribReq() error = '%v'", errAttrib)
return
}
Expand Down Expand Up @@ -607,24 +607,24 @@ func TestBuildAttribRequest(t *testing.T) {
}

type args struct {
Hash string
Raw string
Hash string
Enc string
}
tests := []struct {
name string
args args
wantErr bool
}{
{"build-attrib-request-works-with-raw", args{Hash: "", Raw: raw, Enc: ""}, false},
{"build-attrib-request-works-with-hash", args{Hash: hash, Raw: "", Enc: ""}, false},
{"build-attrib-request-works-with-enc", args{Hash: "", Raw: "", Enc: enc}, false},
{"build-attrib-request-missed-attribute", args{Hash: "", Raw: "", Enc: ""}, true},
{"build-attrib-request-works-with-raw", args{Raw: raw, Hash: "", Enc: ""}, false},
{"build-attrib-request-works-with-hash", args{Raw: "", Hash: hash, Enc: ""}, false},
{"build-attrib-request-works-with-enc", args{Raw: "", Hash: "", Enc: enc}, false},
{"build-attrib-request-missed-attribute", args{Raw: "", Hash: "", Enc: ""}, true},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
requestAttrib, errBuild := BuildAttribRequest(did, targetDid, tt.args.Hash, tt.args.Raw, tt.args.Enc)
requestAttrib, errBuild := BuildAttribRequest(did, targetDid, tt.args.Raw, tt.args.Hash, tt.args.Enc)
hasError := errBuild != nil
if hasError != tt.wantErr {
t.Errorf("BuildAttribRequest() error = '%v'", errBuild)
Expand Down Expand Up @@ -691,19 +691,19 @@ func TestBuildGetAttribRequest(t *testing.T) {
}

type args struct {
Hash string
Raw string
Hash string
Enc string
}
tests := []struct {
name string
args args
wantErr bool
}{
{"build-get-attrib-request-works-with-raw", args{Hash: "", Raw: raw, Enc: ""}, false},
{"build-get-attrib-request-works-with-hash", args{Hash: hash, Raw: "", Enc: ""}, false},
{"build-get-attrib-request-works-with-enc", args{Hash: "", Raw: "", Enc: enc}, false},
{"build-get-attrib-request-missed-attribute", args{Hash: "", Raw: "", Enc: ""}, true},
{"build-get-attrib-request-works-with-raw", args{Raw: raw, Hash: "", Enc: ""}, false},
{"build-get-attrib-request-works-with-hash", args{Raw: "", Hash: hash, Enc: ""}, false},
{"build-get-attrib-request-works-with-enc", args{Raw: "", Hash: "", Enc: enc}, false},
{"build-get-attrib-request-missed-attribute", args{Raw: "", Hash: "", Enc: ""}, true},
}

for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions unitTestsUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ func prepareGetNymReq(poolHandle int, walletHandle int, submitterDid string, tar
}

// prepareGetAttribReq Builds and sends ATTRIB request. Returns GET_ATTRIB request to be sent to ledger.
func prepareGetAttribReq(poolHandle int, walletHandle int, submitterDid string, targetDid string, hash string, raw string, encrypted string) (string, error) {
attribRequest, errAttrib := BuildAttribRequest(targetDid, targetDid, hash, raw, encrypted); if errAttrib != nil {
func prepareGetAttribReq(poolHandle int, walletHandle int, submitterDid string, targetDid string, raw string, hash string, encrypted string) (string, error) {
attribRequest, errAttrib := BuildAttribRequest(targetDid, targetDid, raw, hash, encrypted); if errAttrib != nil {
return "", errAttrib
}
_, errSign := SignAndSubmitRequest(poolHandle, walletHandle, targetDid, attribRequest); if errSign != nil {
Expand Down

0 comments on commit 2e683eb

Please sign in to comment.