Skip to content

Commit

Permalink
Merge pull request #13 from AElfProject/improve/test
Browse files Browse the repository at this point in the history
Improve tests and fix bugs
  • Loading branch information
shiwk authored Jan 27, 2021
2 parents 60f2b3c + 95b7c28 commit 3205ff7
Show file tree
Hide file tree
Showing 13 changed files with 780 additions and 347 deletions.
6 changes: 3 additions & 3 deletions client/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
)

//GetBlockHeight Get height of the current chain.
func (a *AElfClient) GetBlockHeight() (float64, error) {
func (a *AElfClient) GetBlockHeight() (int64, error) {
url := a.Host + BLOCKHEIGHT
heightBytes, err := util.GetRequest("GET", url, a.Version, nil)
if err != nil {
return 0, errors.New("Get BlockHeight error:" + err.Error())
}
var data interface{}
json.Unmarshal(heightBytes, &data)
return data.(float64), nil
return int64(data.(float64)), nil
}

// GetBlockByHash Get information of a block by given block hash. Optional whether to include transaction information.
Expand All @@ -42,7 +42,7 @@ func (a *AElfClient) GetBlockByHash(blockHash string, includeTransactions bool)
}

//GetBlockByHeight Get information of a block by specified height. Optional whether to include transaction information.
func (a *AElfClient) GetBlockByHeight(blockHeight int, includeTransactions bool) (*dto.BlockDto, error) {
func (a *AElfClient) GetBlockByHeight(blockHeight int64, includeTransactions bool) (*dto.BlockDto, error) {
params := map[string]interface{}{
"blockHeight": blockHeight,
"includeTransactions": includeTransactions,
Expand Down
23 changes: 14 additions & 9 deletions dto/block_header_dto.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package dto

import (
"time"
)

//BlockHeaderDto BlockHeaderDto
type BlockHeaderDto struct {
PreviousBlockHash string
MerkleTreeRootOfTransactions string
MerkleTreeRootOfWorldState string
Extra string
Height int64
Time string
ChainId string
Bloom string
SignerPubkey string
PreviousBlockHash string
MerkleTreeRootOfTransactions string
MerkleTreeRootOfWorldState string
MerkleTreeRootOfTransactionState string
Extra string
Height int64
Time time.Time
ChainId string
Bloom string
SignerPubkey string
}
9 changes: 7 additions & 2 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (

"github.com/AElfProject/aelf-sdk.go/client"
"github.com/AElfProject/aelf-sdk.go/dto"
util "github.com/AElfProject/aelf-sdk.go/utils"
"github.com/AElfProject/aelf-sdk.go/utils"
"google.golang.org/protobuf/encoding/protojson"

secp256 "github.com/skycoin/skycoin/src/cipher/secp256k1-go"
)
Expand Down Expand Up @@ -44,13 +45,17 @@ func DemoGetAddressFromPubKey() string {
//DemoExecuteRawTransaction ExecuteRawTransaction demo.
func DemoExecuteRawTransaction() (string, error) {
chainStatus, err := aelf.GetChainStatus()
params := &pb.Hash{
Value: utils.GetBytesSha256("AElf.ContractNames.Token"),
}
paramsByte, _ := protojson.Marshal(params)
var input = &dto.CreateRawTransactionInput{
From: privatekeyAddress,
To: contractAddress,
MethodName: contractMethodName,
RefBlockNumber: chainStatus.BestChainHeight,
RefBlockHash: chainStatus.BestChainHash,
Params: util.ParamsToString("AElf.ContractNames.Consensus"),
Params: string(paramsByte),
}
createRaw, err := aelf.CreateRawTransaction(input)
if err != nil {
Expand Down
126 changes: 63 additions & 63 deletions protobuf/generated/election_contract.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3205ff7

Please sign in to comment.