VM tests
TestABCIService
TestABCIService
TestABCIService
unit test in the service_test.go
file. Overall, the TestABCIService
unit test is testing several methods of the virtual machine service and verifying that they behave as expected.
Here's a breakdown of what the test is doing:
The
TestABCIService
function starts by calling themustNewKVTestVm
function to create a new instance of the virtual machine and virtual machine service, and assigns them to thevm
andservice
variables.The test then runs several subtests using the
t.Run
method, each of which tests a different method of the virtual machine service.
Subtests
ABCIInfo
, tests theABCIInfo
method of the virtual machine service. It creates a newctypes.ResultABCIInfo
variable and passes it to theABCIInfo
method. It then asserts that there is no error returned by the method, and that the response contains the expected values for the app version, last block height, and last block app hash.ABCIQuery
, tests theABCIQuery
method of the virtual machine service. It creates a new key-value transaction using theMakeTxKV
function, broadcasts the transaction using theBroadcastTxSync
method of the virtual machine service, builds and accepts a new block using the virtual machine, and then queries the virtual machine service for the value of the key using theABCIQuery
method. If the query is successful, the subtest asserts that the value returned by the method is equal to the expected value.BroadcastTxCommit
, tests theBroadcastTxCommit
method of the virtual machine service. It creates a new key-value transaction using theMakeTxKV
function, broadcasts the transaction using theBroadcastTxCommit
method of the virtual machine service, and then asserts that theCheckTx
andDeliverTx
fields of the response containtrue
, indicating that the transaction was successfully checked and committed to the blockchain.BroadcastTxAsync
, tests theBroadcastTxAsync
method of the virtual machine service. It creates a new key-value transaction using theMakeTxKV
function, broadcasts the transaction using theBroadcastTxAsync
method of the virtual machine service, and then asserts that theHash
field of the response is notnil
, indicating that the transaction was successfully added to the mempool.BroadcastTxSync
, tests theBroadcastTxSync
method of the virtual machine service. It creates a new key-value transaction using theMakeTxKV
function, broadcasts the transaction using theBroadcastTxSync
method of the virtual machine service, and then asserts that theCode
field of the response is equal toatypes.CodeTypeOK
, indicating that the transaction was successfully checked and committed to the blockchain.
TestHistoryService
TestHistoryService
The TestHistoryService
unit test in the service_test.go
file. Overall, the TestHistoryService
unit test is testing several methods of the virtual machine service related to blockchain history and verifying that they behave as expected. Here's a breakdown of what the test is doing:
The
TestHistoryService
function starts by calling themustNewCounterTestVm
function to create a new instance of the virtual machine and virtual machine service, and assigns them to thevm
andservice
variables.The test then broadcasts a new transaction using the
BroadcastTxSync
method of the virtual machine service and verifies that the response code isatypes.CodeTypeOK
.The test then builds and accepts a new block using the virtual machine.
The test then runs two subtests using the
t.Run
method, each of which tests a different method of the virtual machine service.
Subtests
BlockchainInfo
tests theBlockchainInfo
method of the virtual machine service. It creates a newctypes.ResultBlockchainInfo
variable and passes it to theBlockchainInfo
method with astart
height of1
and anend
height of100
. It then asserts that there is no error returned by the method and that theLastHeight
field of the response is equal to1
.Genesis
tests theGenesis
method of the virtual machine service. It creates a newctypes.ResultGenesis
variable and passes it to theGenesis
method. It then asserts that there is no error returned by the method and that theGenesis
field of the response is equal to the expected value from the virtual machine's genesis configuration.
TestNetworkService
TestNetworkService
The TestNetworkService
unit test in the service_test.go
file. Overall, the TestNetworkService
unit test is testing several methods of the virtual machine service related to networking and consensus and verifying that they behave as expected.
Here's a breakdown of what the test is doing:
The
TestNetworkService
function starts by calling themustNewCounterTestVm
function to create a new instance of the virtual machine and virtual machine service, and assigns them to thevm
andservice
variables.The test then runs five subtests using the
t.Run
method, each of which tests a different method of the virtual machine service related to networking and consensus.
Subtests
NetInfo
tests theNetInfo
method of the virtual machine service. It creates a newctypes.ResultNetInfo
variable and passes it to theNetInfo
method. It then asserts that there is no error returned by the method.DumpConsensusState
tests theDumpConsensusState
method of the virtual machine service. It creates a newctypes.ResultDumpConsensusState
variable and passes it to theDumpConsensusState
method. It then asserts that there is no error returned by the method.ConsensusState
tests theConsensusState
method of the virtual machine service. It creates a newctypes.ResultConsensusState
variable and passes it to theConsensusState
method. It then asserts that there is no error returned by the method.ConsensusParams
tests theConsensusParams
method of the virtual machine service. It creates a newctypes.ResultConsensusParams
variable and passes it to theConsensusParams
method. It then asserts that there is no error returned by the method and that theBlockHeight
field of the response is equal to0
. It then broadcasts a new transaction using theBroadcastTxSync
method of the virtual machine service, builds and accepts a new block using the virtual machine, and asserts that theBlockHeight
field of theConsensusParams
response is equal to1
.Health
tests theHealth
method of the virtual machine service. It creates a newctypes.ResultHealth
variable and passes it to theHealth
method. It then asserts that there is no error returned by the method.
TestSignService
TestSignService
Sure, I can help you document the TestSignService
unit test in the service_test.go
file. Here's a breakdown of what the test is doing:
The
TestSignService
function starts by creating a new key-value transaction (tx
) and creating a new instance of the virtual machine and virtual machine service, which it assigns to thevm
andservice
variables.The test then performs several subtests using the
t.Run
method, each of which tests a different method of the virtual machine service related to signing and verification of transactions.TheTestSignService
has the following subtests:
Subtests
Block
which tests theBlock
method of the virtual machine service with a valid block height. It creates two newctypes.ResultBlock
variables and passes them to theBlock
method with aHeight
parameter of the block height. It then asserts that both methods return anil
error and that theHeight
field of the response is equal to the expected block height.BlockByHash
which tests theBlockByHash
method of the virtual machine service with a valid block hash. It creates two newctypes.ResultBlock
variables and passes them to theBlockByHash
method with aHash
parameter of the block hash. It then asserts that both methods return anil
error and that theHash
field of the response is equal to the expected block hash.BlockResults
which tests theBlockResults
method of the virtual machine service with a valid block height. It creates two newctypes.ResultBlockResults
variables and passes them to theBlockResults
method with aHeight
parameter of the block height. It then asserts that both methods return anil
error and that theHeight
field of the response is equal to the expected block height.Tx
which tests theTx
method of the virtual machine service with a valid transaction hash. It creates a newctypes.ResultTx
variable and passes it to theTx
method with aHash
parameter of the transaction hash. It then asserts that the method returns anil
error and that theHash
andTx
fields of the response are equal to the expected transaction hash and transaction, respectively.
Overall, the TestSignService
unit test is testing several methods of the virtual machine service related to signing and verification of transactions and verifying that they behave as expected.
TestStatusService
TestStatusService
The TestStatusService
unit test in the service_test.go
file. Here's a breakdown of what the test is doing:
The
TestStatusService
function starts by creating a new instance of the virtual machine and virtual machine service, which it assigns to thevm
andservice
variables.The test then attempts to build a new block from the virtual machine with no pending transactions. It expects this operation to fail with an
errNoPendingTxs
error and anil
block.Next, the test creates a new key-value transaction (
tx
) and uses theBroadcastTxSync
method of the virtual machine service to broadcast the transaction. It asserts that the method returns no error and that theCode
field of the response is equal toatypes.CodeTypeOK
.The test then creates a new subtest using the
t.Run
method, which tests theStatus
method of the virtual machine service with two different blocks. It creates two newctypes.ResultStatus
variables and passes them to theStatus
method. The first call is made with no arguments and expects the response to contain aLatestBlockHeight
field with a value of0
. The second call is made after successfully building and accepting a new block and expects the response to contain aLatestBlockHeight
field with a value of1
.
Overall, the TestStatusService
unit test is testing the Status
method of the virtual machine service with two different blocks and verifying that the expected block height is returned in the response.
TestMempoolService
TestMempoolService
This unit test suite tests the functionalities of the MempoolService
struct.
Sub-tests:
UnconfirmedTxs
Description: Tests the functionality of retrieving unconfirmed transactions in the mempool.
Steps:
Build a transaction and broadcast it to the mempool.
Call the
UnconfirmedTxs
function of theMempoolService
.
Expected Results: The function should return the single transaction that was broadcasted to the mempool.
NumUnconfirmedTxs
Description: Tests the functionality of retrieving the number of unconfirmed transactions in the mempool.
Steps:
Build a transaction and broadcast it to the mempool.
Call the
NumUnconfirmedTxs
function of theMempoolService
.
Expected Results: The function should return a count of 1, indicating the single transaction that was broadcasted to the mempool.
CheckTx
Description: Tests the functionality of checking if a transaction is valid and can be accepted into the mempool.
Steps:
Build a transaction and broadcast it to the mempool.
Call the
CheckTx
function of theMempoolService
with the same transaction.Build a block and accept it.
Call the
CheckTx
function of theMempoolService
with the same transaction.
Expected Results:
The first
CheckTx
function should return no errors, indicating the transaction is valid and can be accepted into the mempool.The second
CheckTx
function should return an error, indicating the transaction has already been accepted into the blockchain and cannot be accepted into the mempool again.
Last updated