Skip to content

Commit

Permalink
Merge pull request #78 from proximax-storage/mosaic_fix
Browse files Browse the repository at this point in the history
mosaic_fix
  • Loading branch information
BramBear authored Oct 12, 2018
2 parents 12b812d + 64c56bf commit 8bcb806
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 7 deletions.
108 changes: 108 additions & 0 deletions sdk/mosaic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,114 @@ func TestMosaicService_GetMosaicsFromNamespace(t *testing.T) {
t.Error(err)
} else if validateResp(resp, t) {
t.Logf("%v", mscInfoArr)
}

nsId, _ := (&big.Int{}).SetString("12143912612286323120", 10)
mscInfoArr, resp, err = serv.Mosaic.GetMosaicsFromNamespace(ctx, &NamespaceId{Id: nsId}, nil, pageSize)
if err != nil {
t.Error(err)
} else if validateResp(resp, t) {
t.Logf("%v", mscInfoArr)

}

}

const iter = 1000

func TestMosaicService_GetMosaicsFromNamespasceExt(t *testing.T) {

cfg, _ := LoadMainnetConfig("http://190.216.224.11:3000")

serv := NewClient(nil, cfg)

h, _, err := serv.Blockchain.GetBlockchainHeight(ctx)
if err != nil {
t.Fatal(err)
}

for i := uint64(1); i < h.Uint64() && i <= iter; i++ {

h := big.NewInt(int64(i))
trans, _, err := serv.Blockchain.GetBlockTransactions(ctx, h)
if err != nil {
t.Fatal(err)
continue
}

if len(trans) == 0 {
t.Logf("%d block, empty transactiona", h)
}

for j, val := range trans {
if val == nil {
t.Logf("empty trans #%d", j)
continue
}
//t.Log(val.String())
switch val.GetAbstractTransaction().Type {
case MosaicDefinition:
tran := val.(*MosaicDefinitionTransaction)

if tran.NamespaceId == nil {
t.Logf("empty nsId or MosaicId")
t.Log(tran)
continue
}
mscInfoArr, resp, err := serv.Mosaic.GetMosaicsFromNamespace(ctx, tran.NamespaceId, tran.MosaicId, pageSize)
if err != nil {
t.Error(err)
} else if validateResp(resp, t) {
for _, mscInfo := range mscInfoArr {
t.Logf("%+v", mscInfo)
}
}
case MosaicSupplyChange:
tran := val.(*MosaicSupplyChangeTransaction)

if tran.MosaicId == nil {
t.Logf("empty MosaicId")
t.Log(tran)
continue
}
mscInfo, resp, err := serv.Mosaic.GetMosaic(ctx, *tran.MosaicId)
if err != nil {
t.Error(err)
} else if validateResp(resp, t) {
t.Logf("%+v", mscInfo)
}
case Transfer:
tran := val.(*TransferTransaction)
if tran.Mosaics == nil {
t.Logf("empty Mosaics")
t.Log(tran)
continue
}
mosaicIDs := MosaicIds{}
for _, val := range tran.Mosaics {
mosaicIDs.MosaicIds = append(mosaicIDs.MosaicIds, val.MosaicId)
}
mscInfoArr, resp, err := serv.Mosaic.GetMosaicNames(ctx, mosaicIDs)
if err != nil {
t.Error(err)
} else if validateResp(resp, t) {
for _, mscInfo := range mscInfoArr {
t.Logf("%+v", mscInfo)

}
}
case RegisterNamespace:
tran := val.(*RegisterNamespaceTransaction)
nsInfo, resp, err := serv.Namespace.GetNamespace(ctx, tran.NamespaceId)
if err != nil {
t.Error(err)
} else if validateResp(resp, t) {
t.Logf("%#v", nsInfo)
}
default:
t.Log(val)
}
}

}

Expand Down
9 changes: 5 additions & 4 deletions sdk/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import (
// NamespaceService provides a set of methods for obtaining information about the namespace
type NamespaceService service

func NewNamespaceService(httpClient *http.Client, conf *Config) *NamespaceService {
return &NamespaceService{client: NewClient(httpClient, conf)}
}

//GetNamespace
// @/namespace/
func (ref *NamespaceService) GetNamespace(ctx context.Context, nsId *NamespaceId) (nsInfo *NamespaceInfo, resp *http.Response, err error) {

nsInfoDTO := &namespaceInfoDTO{}
Expand All @@ -36,6 +34,7 @@ func (ref *NamespaceService) GetNamespace(ctx context.Context, nsId *NamespaceId
}

// GetNamespaceNames
//@/namespace/names
func (ref *NamespaceService) GetNamespaceNames(ctx context.Context, nsIds NamespaceIds) (nsList []*NamespaceName, resp *http.Response, err error) {

if len(nsIds.List) == 0 {
Expand All @@ -59,6 +58,7 @@ func (ref *NamespaceService) GetNamespaceNames(ctx context.Context, nsIds Namesp
}

// GetNamespacesFromAccount get required params addresses, other skipped if value < 0
// @/account/%s/namespaces
func (ref *NamespaceService) GetNamespacesFromAccount(ctx context.Context, address *Address, nsId string,
pageSize int) (nsList ListNamespaceInfo, resp *http.Response, err error) {

Expand Down Expand Up @@ -91,6 +91,7 @@ func (ref *NamespaceService) GetNamespacesFromAccount(ctx context.Context, addre
}

// GetNamespacesFromAccounts get required params addresses, other skipped if value is empty
// @/account/namespaces
func (ref *NamespaceService) GetNamespacesFromAccounts(ctx context.Context, addresses *Addresses, nsId string,
pageSize int) (nsList ListNamespaceInfo, resp *http.Response, err error) {

Expand Down
36 changes: 34 additions & 2 deletions test/http/blockchain_test.http
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
# get namespace Info
GET http://localhost:3000/blocks/{height}/limit/{limit}
GET http://190.216.224.11:3000/blocks/{height}/limit/{limit}
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Cache-Control: no-cache

###

GET http://localhost:3000/blocks/height
GET http://190.216.224.11:3000/chain/height
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Cache-Control: no-cache

####

GET http://190.216.224.11:3000/block/1
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Cache-Control: no-cache

####

GET http://190.216.224.11:3000/block/1/transactions
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Cache-Control: no-cache

####

GET http://190.216.224.11:3000/diagnostic/storage
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Cache-Control: no-cache

####

GET http://190.216.224.11:3000/blocks/height
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Expand Down
20 changes: 19 additions & 1 deletion test/http/mosaic_test.http
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,25 @@ Cache-Control: no-cache
###

# Get mosaics information
GET http://localhost:3000/namespace/84b3552d375ffa4b/mosaics?id=5B55E02EACCB7B00015DB6EC&pagesize=32
GET http://localhost:3000/namespace/84b3552d375ffa4b/mosaics?id=d525ad41d95fcf29&pagesize=32
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Cache-Control: no-cache

###

# Get mosaics information
GET http://190.216.224.11:3000/namespace/a887d82dfeb659b0/mosaics?id=4f95ab513876a2bd&pagesize=32
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Cache-Control: no-cache

###

# Get mosaics information
GET http://190.216.224.11:3000/namespace/a887d82dfeb659b0/mosaics?pagesize=32
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Expand Down
8 changes: 8 additions & 0 deletions test/http/transaction.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

GET http://190.216.224.11:3000/transaction/5B55E02EACCB7B00015DB6E1
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Cache-Control: no-cache

####

0 comments on commit 8bcb806

Please sign in to comment.