utils

package module
v0.0.0-...-6b52464 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 22 Imported by: 0

README

testnet-util

A set of modules with functions for testing projects

TOC

Description

A set of modules with functions for testing projects

License

Default license

Documentation

Index

Constants

View Source
const (
	// HlfProxyURL - domain and port for hlf proxy service, example http://localhost:9001 without '/' on the end the string
	HlfProxyURL = "HLF_PROXY_URL"
	// HlfProxyAuthToken - support Basic Auth with auth token
	HlfProxyAuthToken = "HLF_PROXY_AUTH_TOKEN" //nolint:gosec
	// FiatIssuerPrivateKey - issuer private key ed25519 in base58 check
	FiatIssuerPrivateKey = "FIAT_ISSUER_PRIVATE_KEY"
	// BatchTransactionTimeout - common time execution of following process
	// robot - defaultBatchLimits.batchTimeoutLimit
	// Time batch execute by robot
	BatchTransactionTimeout = 2 * time.Second
	// ObserverAPIURL - domain and port for observer service, example http://localhost:3335/api without '/' on the end the string
	ObserverAPIURL = "OBSERVER_API_URL"
	// CorrectNodeName Name of any node from stand
	CorrectNodeName = "CORRECT_NODE_NAME"
	// DefaultSwapHash - default swap hash
	DefaultSwapHash = "7d4e3eec80026719639ed4dba68916eb94c7a49a053e05c8f9578fe4e5a3d7ea" // #nosec G101
	// DefaultSwapKey - default swap key
	DefaultSwapKey = "12345"
	// InvokeTimeout sets timeout for invoke method operations
	InvokeTimeout = 10 * time.Second
	// QueryTimeout sets timeout for query method operations
	QueryTimeout = 10 * time.Second
	// MoreNonceTTL sets timeout for nonce
	MoreNonceTTL = 11 * time.Second
)

Variables

This section is empty.

Functions

func AddUserGetResponce

func AddUserGetResponce(t provider.T, hlfProxy HlfProxyService) (User, *Response)

AddUserGetResponce adds user and returns response

func AsBytes

func AsBytes(args ...string) [][]byte

AsBytes converts string to [][]byte

func CheckAllowedBalanceEqual

func CheckAllowedBalanceEqual(t provider.T, hlfProxy HlfProxyService, userAddressBase58Check string, channel string, tokenUppercase string, amount string)

CheckAllowedBalanceEqual checks that allowed balance of userAddressBase58Check is equal to amount

func CheckBalanceEqual

func CheckBalanceEqual(t provider.T, hlfProxy HlfProxyService, userAddressBase58Check string, channel string, amount string)

CheckBalanceEqual checks that balance of userAddressBase58Check is equal to amount

func CheckBalanceEqualWithRetry

func CheckBalanceEqualWithRetry(t provider.T, hlfProxy HlfProxyService, userAddressBase58Check string, channel string, amount string, sleep time.Duration, retries int)

CheckBalanceEqualWithRetry checks that balance of userAddressBase58Check is equal to amount with retries

func CheckStatusCode

func CheckStatusCode(t provider.T, expectedResponseCode int, actualResponseCode int)

CheckStatusCode checks that status code is equal to expected

func ConvertPemTox509certificate

func ConvertPemTox509certificate(bytes []byte) (*x509.Certificate, error)

ConvertPemTox509certificate converts pem to x509 certificate

func ConvertPublicKeyToBase58

func ConvertPublicKeyToBase58(publicKey ed25519.PublicKey) string

ConvertPublicKeyToBase58 - use publicKey with standard encoded type - Base58

func EmitGetTxIDAndCheckBalance

func EmitGetTxIDAndCheckBalance(
	t provider.T,
	hlfProxy HlfProxyService,
	userAddressBase58Check string,
	issuer Issuer,
	channel string,
	chaincode string,
	amount string,
) string

EmitGetTxIDAndCheckBalance emits amount of tokens to userAddressBase58Check and checks that balance is equal to amount

func FillStructFromBody

func FillStructFromBody(t provider.T, body []byte, tt any)

FillStructFromBody fills struct from body\

func GeneratePrivateAndPublicKey

func GeneratePrivateAndPublicKey() (ed25519.PrivateKey, ed25519.PublicKey, error)

GeneratePrivateAndPublicKey - create new private and public key

func GenerateUserPublicKeyBase58

func GenerateUserPublicKeyBase58(t provider.T) string

GenerateUserPublicKeyBase58 generates user public key base58

func GetAddressByPublicKey

func GetAddressByPublicKey(publicKey ed25519.PublicKey) (string, error)

GetAddressByPublicKey - get address by encoded string in standard encoded for project is 'base58.Check'

func GetEmitPayload

func GetEmitPayload(
	t provider.T,
	hlfProxy HlfProxyService,
	userAddressBase58Check string,
	issuer Issuer,
	amount string,
) string

GetEmitPayload emits amount of tokens to userAddressBase58Check and checks that balance is equal to amount

func GetEnv

func GetEnv(key, defaultValue string) string

GetEnv return env if found or defaultValue if not found

func GetNonce

func GetNonce() string

GetNonce returns nonce

func GetPrivateKeyFromBase58Check

func GetPrivateKeyFromBase58Check(secretKey string) (ed25519.PrivateKey, ed25519.PublicKey, error)

GetPrivateKeyFromBase58Check - get private key type Ed25519 by string - Base58Check encoded private key

func MakeJSONArrayFromNdJSON

func MakeJSONArrayFromNdJSON(body []byte) string

MakeJSONArrayFromNdJSON converts NDJSON to JSON array

func MultisigHex

func MultisigHex(methodName string, args []string, users ...User) ([]string, error)

MultisigHex - added multisign in HEX

func MultisigHexWithNonce

func MultisigHexWithNonce(methodName string, args []string, nonce string, users ...User) ([]string, error)

MultisigHexWithNonce - added multisign in HEX with nonce

func Sign

func Sign(privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey, channel string, chaincode string, methodName string, args []string) ([]string, error)

Sign - sign arguments before send to hlf. create message with certain order arguments expected by chaincode validation in foundation library

func SignExpand

func SignExpand(privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey, channel string, chaincode string, methodName string, args []string, nonce string, externalRequestID string) ([]string, error)

SignExpand - sign arguments before send to hlf. create message with certain order arguments expected by chaincode validation in foundation library

func SignHex

func SignHex(privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey, methodName string, args []string) ([]string, error)

SignHex - sign arguments in HEX before send to hlf. create message with certain order arguments expected by chaincode validation in foundation library

func SignHexWithNonce

func SignHexWithNonce(privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey, methodName string, args []string, nonce string) ([]string, error)

SignHexWithNonce - sign arguments in HEX before send to hlf. create message with certain order arguments expected by chaincode validation in foundation library

func SignWithNonce

func SignWithNonce(privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey, channel string, chaincode string, methodName string, args []string, nonce string) ([]string, error)

SignWithNonce - sign arguments before send to hlf. create message with certain order arguments expected by chaincode validation in foundation library

func SwapFiatToCCCheckBalanceAndGetSwapDoneAndSwapBeginTxID

func SwapFiatToCCCheckBalanceAndGetSwapDoneAndSwapBeginTxID(t provider.T, hlfProxy HlfProxyService, user User, amount string) (string, string)

SwapFiatToCCCheckBalanceAndGetSwapDoneAndSwapBeginTxID swaps amount of tokens from fiat to cc channel

Types

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient struct url - domain and port for observer service, example http://localhost:3335/api without '/' on the end the string. HTTPClient is used to send requests to observer service.

func NewHTTPClient

func NewHTTPClient(url ...string) *HTTPClient

NewHTTPClient - create new instance of HTTPClient

func (*HTTPClient) Get

func (o *HTTPClient) Get(t provider.T, apiPath string) ([]byte, int)

Get - send GET request to observer service

func (*HTTPClient) Post

func (o *HTTPClient) Post(t provider.T, apiPath string, v any) ([]byte, int)

Post - send POST request to observer service

func (*HTTPClient) PrepareURL

func (o *HTTPClient) PrepareURL(t provider.T, apiPath string) string

PrepareURL - prepare url for request

type HlfProxyService

type HlfProxyService struct {
	// contains filtered or unexported fields
}

HlfProxyService struct url - domain and port for hlf proxy service, example http://localhost:9001 without '/' on the end the string authToken - support Basic Auth with auth token

func NewHlfProxyService

func NewHlfProxyService(url string, authToken string) *HlfProxyService

NewHlfProxyService - create new instance of HlfProxyService

func (*HlfProxyService) GetPayloadInvoke

func (p *HlfProxyService) GetPayloadInvoke(chaincodeID string, fcn string, args ...string) ([]byte, error)

GetPayloadInvoke - send invoke request to hlf through hlf proxy service

func (*HlfProxyService) GetPayloadQuery

func (p *HlfProxyService) GetPayloadQuery(chaincodeID string, fcn string, args ...string) ([]byte, error)

GetPayloadQuery - send query request to hlf through hlf proxy service

func (*HlfProxyService) Invoke

func (p *HlfProxyService) Invoke(chaincodeID string, fcn string, args ...string) (*Response, error)

Invoke - send invoke request to hlf through hlf proxy service

func (*HlfProxyService) Query

func (p *HlfProxyService) Query(chaincodeID string, fcn string, args ...string) (*Response, error)

Query - send query request to hlf through hlf proxy service

type Issuer

type Issuer struct {
	IssuerEd25519PrivateKey      ed25519.PrivateKey
	IssuerEd25519PublicKey       ed25519.PublicKey
	IssuerEd25519PublicKeyBase58 string
}

Issuer struct

func AddIssuer

func AddIssuer(t provider.T, hlfProxy HlfProxyService, base58Check string) Issuer

AddIssuer adds issuer

type Options

type Options struct {
	TargetEndpoints []string `json:"targetEndpoints"`
}

Options that can be used to specify target endpoints for the transaction invocation.

type Request

type Request struct {
	Args        [][]byte `json:"args"`
	ChaincodeID string   `json:"chaincodeId"`
	Fcn         string   `json:"fcn"`
}

Request struct for request to hlf proxy

type RequestPrx

type RequestPrx struct {
	Args        [][]byte `json:"args"`
	ChaincodeID string   `json:"chaincodeId"`
	Fcn         string   `json:"fcn"`
	Opts        *Options `json:"options,omitempty"`
}

RequestPrx struct for request to hlf proxy

type Response

type Response struct {
	BlockNumber      int64  `json:"blockNumber,omitempty"`
	ChaincodeStatus  int64  `json:"chaincodeStatus,omitempty"`
	Payload          []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
	TransactionID    string `json:"transactionId,omitempty"`
	TxValidationCode int64  `json:"txValidationCode,omitempty"`
}

Response struct for response from hlf proxy

func EmitGetResponseAndCheckBalance

func EmitGetResponseAndCheckBalance(
	t provider.T,
	hlfProxy HlfProxyService,
	userAddressBase58Check string,
	iss Issuer,
	channel string,
	chaincode string,
	amount string,
) *Response

EmitGetResponseAndCheckBalance emits amount of tokens to userAddressBase58Check and checks that balance is equal to amount

func TransferCheckBalanceAndGetRespose

func TransferCheckBalanceAndGetRespose(
	t provider.T,
	hlfProxy HlfProxyService,
	userFrom User,
	userToAddress string,
	channel string,
	chaincode string,
	amount string,
) *Response

TransferCheckBalanceAndGetRespose transfers amount of tokens from userFrom to userToAddress and checks that balance of userToAddress is equal to amount

type ResponseError

type ResponseError struct {
	Code    int64  `json:"code"`
	Message string `json:"message"`
}

ResponseError struct for response error from hlf proxy

type ResponseErrorPrx

type ResponseErrorPrx struct {
	Code    int64  `json:"code"`
	Message string `json:"message"`
}

ResponseErrorPrx struct for response error from hlf proxy

type ResponsePrx

type ResponsePrx struct {
	BlockNumber      int64  `json:"blockNumber,omitempty"`
	ChaincodeStatus  int64  `json:"chaincodeStatus,omitempty"`
	Payload          []byte `json:"payload,omitempty"`
	TransactionID    string `json:"transactionId,omitempty"`
	TxValidationCode int64  `json:"txValidationCode,omitempty"`
}

ResponsePrx struct for response from hlf proxy

func Invoke

func Invoke(ctx context.Context, url, token, cc, fcn string, endpoints []string, args ...string) (*ResponsePrx, error)

Invoke ...

func Query

func Query(ctx context.Context, url, token, cc, fcn string, endpoints []string, args ...string) (*ResponsePrx, error)

Query ...

type User

type User struct {
	UserEd25519PrivateKey  ed25519.PrivateKey
	UserEd25519PublicKey   ed25519.PublicKey
	UserPublicKeyBase58    string
	UserAddressBase58Check string
}

User struct

func AddUser

func AddUser(t provider.T, hlfProxy HlfProxyService) User

AddUser adds user

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL