@@ -112,7 +112,7 @@ type esdtTokensCompleteResponseData struct {
112112type esdtTokensCompleteResponse struct {
113113 Data esdtTokensCompleteResponseData `json:"data"`
114114 Error string `json:"error"`
115- Code string
115+ Code string `json:"code"`
116116}
117117
118118type keyValuePairsResponseData struct {
@@ -122,7 +122,17 @@ type keyValuePairsResponseData struct {
122122type keyValuePairsResponse struct {
123123 Data keyValuePairsResponseData `json:"data"`
124124 Error string `json:"error"`
125- Code string
125+ Code string `json:"code"`
126+ }
127+
128+ type iterateKeysResponseData struct {
129+ Pairs map [string ]string `json:"pairs"`
130+ NewIteratorState [][]byte `json:"newIteratorState"`
131+ }
132+ type iterateKeysResponse struct {
133+ Data iterateKeysResponseData `json:"data"`
134+ Error string `json:"error"`
135+ Code string `json:"code"`
126136}
127137
128138type esdtRolesResponseData struct {
@@ -132,7 +142,7 @@ type esdtRolesResponseData struct {
132142type esdtRolesResponse struct {
133143 Data esdtRolesResponseData `json:"data"`
134144 Error string `json:"error"`
135- Code string
145+ Code string `json:"code"`
136146}
137147
138148type usernameResponseData struct {
@@ -662,6 +672,106 @@ func TestAddressGroup_getKeyValuePairs(t *testing.T) {
662672 })
663673}
664674
675+ func TestAddressGroup_iterateKeys (t * testing.T ) {
676+ t .Parallel ()
677+
678+ t .Run ("invalid body should error" ,
679+ testErrorScenario ("/address/iterate-keys" , "POST" , bytes .NewBuffer ([]byte ("invalid body" )),
680+ formatExpectedErr (apiErrors .ErrValidation , errors .New ("invalid character 'i' looking for beginning of value" ))))
681+ t .Run ("empty address should error" , func (t * testing.T ) {
682+ t .Parallel ()
683+
684+ body := & groups.IterateKeysRequest {
685+ Address : "" ,
686+ }
687+ bodyBytes , _ := json .Marshal (body )
688+ testAddressGroup (
689+ t ,
690+ & mock.FacadeStub {},
691+ "/address/iterate-keys" ,
692+ "POST" ,
693+ bytes .NewBuffer (bodyBytes ),
694+ http .StatusBadRequest ,
695+ formatExpectedErr (apiErrors .ErrValidation , apiErrors .ErrEmptyAddress ),
696+ )
697+ })
698+ t .Run ("invalid query options should error" , func (t * testing.T ) {
699+ t .Parallel ()
700+
701+ body := & groups.IterateKeysRequest {
702+ Address : "erd1" ,
703+ }
704+ bodyBytes , _ := json .Marshal (body )
705+ testAddressGroup (
706+ t ,
707+ & mock.FacadeStub {},
708+ "/address/iterate-keys?blockNonce=not-uint64" ,
709+ "POST" ,
710+ bytes .NewBuffer (bodyBytes ),
711+ http .StatusBadRequest ,
712+ formatExpectedErr (apiErrors .ErrIterateKeys , apiErrors .ErrBadUrlParams ),
713+ )
714+ })
715+ t .Run ("with node fail should err" , func (t * testing.T ) {
716+ t .Parallel ()
717+
718+ body := & groups.IterateKeysRequest {
719+ Address : "erd1" ,
720+ }
721+ bodyBytes , _ := json .Marshal (body )
722+ facade := & mock.FacadeStub {
723+ IterateKeysCalled : func (address string , numKeys uint , iteratorState [][]byte , options api.AccountQueryOptions ) (map [string ]string , [][]byte , api.BlockInfo , error ) {
724+ return nil , nil , api.BlockInfo {}, expectedErr
725+ },
726+ }
727+ testAddressGroup (
728+ t ,
729+ facade ,
730+ "/address/iterate-keys" ,
731+ "POST" ,
732+ bytes .NewBuffer (bodyBytes ),
733+ http .StatusInternalServerError ,
734+ formatExpectedErr (apiErrors .ErrIterateKeys , expectedErr ),
735+ )
736+ })
737+ t .Run ("should work" , func (t * testing.T ) {
738+ t .Parallel ()
739+
740+ pairs := map [string ]string {
741+ "k1" : "v1" ,
742+ "k2" : "v2" ,
743+ }
744+
745+ body := & groups.IterateKeysRequest {
746+ Address : "erd1" ,
747+ NumKeys : 10 ,
748+ IteratorState : [][]byte {[]byte ("starting" ), []byte ("state" )},
749+ }
750+ newIteratorState := [][]byte {[]byte ("new" ), []byte ("state" )}
751+ bodyBytes , _ := json .Marshal (body )
752+ facade := & mock.FacadeStub {
753+ IterateKeysCalled : func (address string , numKeys uint , iteratorState [][]byte , options api.AccountQueryOptions ) (map [string ]string , [][]byte , api.BlockInfo , error ) {
754+ assert .Equal (t , body .Address , address )
755+ assert .Equal (t , body .NumKeys , numKeys )
756+ assert .Equal (t , body .IteratorState , iteratorState )
757+ return pairs , newIteratorState , api.BlockInfo {}, nil
758+ },
759+ }
760+
761+ response := & iterateKeysResponse {}
762+ loadAddressGroupResponse (
763+ t ,
764+ facade ,
765+ "/address/iterate-keys" ,
766+ "POST" ,
767+ bytes .NewBuffer (bodyBytes ),
768+ response ,
769+ )
770+ assert .Equal (t , pairs , response .Data .Pairs )
771+ assert .Equal (t , newIteratorState , response .Data .NewIteratorState )
772+ })
773+ }
774+
665775func TestAddressGroup_getESDTBalance (t * testing.T ) {
666776 t .Parallel ()
667777
@@ -1143,6 +1253,7 @@ func getAddressRoutesConfig() config.ApiRoutesConfig {
11431253 {Name : "/:address/username" , Open : true },
11441254 {Name : "/:address/code-hash" , Open : true },
11451255 {Name : "/:address/keys" , Open : true },
1256+ {Name : "/iterate-keys" , Open : true },
11461257 {Name : "/:address/key/:key" , Open : true },
11471258 {Name : "/:address/esdt" , Open : true },
11481259 {Name : "/:address/esdts/roles" , Open : true },
0 commit comments