Skip to content

Commit

Permalink
Fix transactions in blockchain check negative tests (#1105)
Browse files Browse the repository at this point in the history
* Fix negative cases and case info messages

* Fix case info messages

---------

Co-authored-by: Alexey Kiselev <[email protected]>
  • Loading branch information
irina-pereiaslavskaia and alexeykiselev authored May 23, 2023
1 parent 65dcaa1 commit e53aedd
Show file tree
Hide file tree
Showing 18 changed files with 759 additions and 655 deletions.
112 changes: 63 additions & 49 deletions itests/alias_tx_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ func (suite *AliasTxApiSuite) Test_AliasTxApiPositive() {
for _, v := range versions {
tdmatrix := testdata.GetAliasPositiveDataMatrix(&suite.BaseSuite)
for name, td := range tdmatrix {
suite.Run(utl.GetTestcaseNameWithVersion(name, v), func() {
tx, _, actualDiffBalanceInWaves := alias_utilities.BroadcastAliasTxAndGetWavesBalances(&suite.BaseSuite, td, v, waitForTx)
utl.StatusCodesCheck(suite.T(), http.StatusOK, http.StatusOK, tx, utl.GetTestcaseNameWithVersion(name, v))
caseName := utl.GetTestcaseNameWithVersion(name, v)
suite.Run(caseName, func() {
tx, _, actualDiffBalanceInWaves := alias_utilities.BroadcastAliasTxAndGetWavesBalances(&suite.BaseSuite,
td, v, waitForTx)
errMsg := caseName + "Broadcast Alias Tx: " + tx.TxID.String()
addrByAliasGo, addrByAliasScala := utl.GetAddressesByAlias(&suite.BaseSuite, td.Alias)

utl.TxInfoCheck(suite.T(), tx.WtErr.ErrWtGo, tx.WtErr.ErrWtScala, utl.GetTestcaseNameWithVersion(name, v), tx.TxID.String())
utl.StatusCodesCheck(suite.T(), http.StatusOK, http.StatusOK, tx, errMsg)
utl.TxInfoCheck(suite.T(), tx.WtErr.ErrWtGo, tx.WtErr.ErrWtScala, errMsg)
utl.AddressByAliasCheck(suite.T(), td.Expected.ExpectedAddress.Bytes(), addrByAliasGo, addrByAliasScala,
errMsg)
utl.WavesDiffBalanceCheck(suite.T(), td.Expected.WavesDiffBalance, actualDiffBalanceInWaves.BalanceInWavesGo,
actualDiffBalanceInWaves.BalanceInWavesScala, utl.GetTestcaseNameWithVersion(name, v))
actualDiffBalanceInWaves.BalanceInWavesScala, errMsg)
})
}
}
Expand All @@ -43,15 +49,19 @@ func (suite *AliasTxApiSuite) Test_AliasTxApiMaxValuesPositive() {
utl.DefaultAccountForLoanFunds, 10000000000)
tdmatrix := testdata.GetAliasMaxPositiveDataMatrix(&suite.BaseSuite, n)
for name, td := range tdmatrix {
suite.Run(utl.GetTestcaseNameWithVersion(name, v), func() {
caseName := utl.GetTestcaseNameWithVersion(name, v)
suite.Run(caseName, func() {
tx, _, actualDiffBalanceInWaves := alias_utilities.BroadcastAliasTxAndGetWavesBalances(&suite.BaseSuite,
td, v, waitForTx)
errMsg := caseName + "Broadcast Alias Tx: " + tx.TxID.String()
addrByAliasGo, addrByAliasScala := utl.GetAddressesByAlias(&suite.BaseSuite, td.Alias)

utl.StatusCodesCheck(suite.T(), http.StatusOK, http.StatusOK, tx, utl.GetTestcaseNameWithVersion(name, v))

utl.TxInfoCheck(suite.T(), tx.WtErr.ErrWtGo, tx.WtErr.ErrWtScala, utl.GetTestcaseNameWithVersion(name, v), tx.TxID.String())
utl.StatusCodesCheck(suite.T(), http.StatusOK, http.StatusOK, tx, errMsg)
utl.TxInfoCheck(suite.T(), tx.WtErr.ErrWtGo, tx.WtErr.ErrWtScala, errMsg)
utl.AddressByAliasCheck(suite.T(), td.Expected.ExpectedAddress.Bytes(), addrByAliasGo, addrByAliasScala,
errMsg)
utl.WavesDiffBalanceCheck(suite.T(), td.Expected.WavesDiffBalance, actualDiffBalanceInWaves.BalanceInWavesGo,
actualDiffBalanceInWaves.BalanceInWavesScala, utl.GetTestcaseNameWithVersion(name, v))
actualDiffBalanceInWaves.BalanceInWavesScala, errMsg)
})
}
}
Expand All @@ -60,117 +70,121 @@ func (suite *AliasTxApiSuite) Test_AliasTxApiMaxValuesPositive() {
func (suite *AliasTxApiSuite) Test_AliasTxApiNegative() {
versions := alias_utilities.GetVersions(&suite.BaseSuite)
waitForTx := false
txIds := make(map[string]*crypto.Digest)
for _, v := range versions {
tdmatrix := testdata.GetAliasNegativeDataMatrix(&suite.BaseSuite)
txIds := make(map[string]*crypto.Digest)
for name, td := range tdmatrix {
suite.Run(utl.GetTestcaseNameWithVersion(name, v), func() {
caseName := utl.GetTestcaseNameWithVersion(name, v)
suite.Run(caseName, func() {
tx, _, actualDiffBalanceInWaves := alias_utilities.BroadcastAliasTxAndGetWavesBalances(&suite.BaseSuite,
td, v, waitForTx)

utl.StatusCodesCheck(suite.T(), http.StatusInternalServerError, http.StatusBadRequest, tx,
utl.GetTestcaseNameWithVersion(name, v))
utl.ErrorMessageCheck(suite.T(), td.Expected.ErrBrdCstGoMsg, td.Expected.ErrBrdCstScalaMsg,
tx.BrdCstErr.ErrorBrdCstGo, tx.BrdCstErr.ErrorBrdCstScala, utl.GetTestcaseNameWithVersion(name, v))
txIds[name] = &tx.TxID
errMsg := caseName + "Broadcast Alias Tx: " + tx.TxID.String()

utl.StatusCodesCheck(suite.T(), http.StatusInternalServerError, http.StatusBadRequest, tx, errMsg)
utl.ErrorMessageCheck(suite.T(), td.Expected.ErrBrdCstGoMsg, td.Expected.ErrBrdCstScalaMsg,
tx.BrdCstErr.ErrorBrdCstGo, tx.BrdCstErr.ErrorBrdCstScala, errMsg)
utl.ErrorMessageCheck(suite.T(), td.Expected.ErrGoMsg, td.Expected.ErrScalaMsg, tx.WtErr.ErrWtGo,
tx.WtErr.ErrWtScala, utl.GetTestcaseNameWithVersion(name, v))
tx.WtErr.ErrWtScala, errMsg)
utl.WavesDiffBalanceCheck(suite.T(), td.Expected.WavesDiffBalance, actualDiffBalanceInWaves.BalanceInWavesGo,
actualDiffBalanceInWaves.BalanceInWavesScala, utl.GetTestcaseNameWithVersion(name, v))
actualDiffBalanceInWaves.BalanceInWavesScala, errMsg)
})
}
actualTxIds := utl.GetTxIdsInBlockchain(&suite.BaseSuite, txIds)
suite.Lenf(actualTxIds, 0, "IDs: %#v", actualTxIds, "Version: %#v", v)
}
actualTxIds := utl.GetTxIdsInBlockchain(&suite.BaseSuite, txIds)
suite.Lenf(actualTxIds, 0, "IDs: %#v", actualTxIds)
}

func (suite *AliasTxApiSuite) Test_SameAliasApiNegative() {
versions := alias_utilities.GetVersions(&suite.BaseSuite)
waitForTx := true
name := "Values for same alias"
//Count of tx id in blockchain after tx, for v1 and v2 it should be 2: 1 for each node
var idsCount = 2
txIds := make(map[string]*crypto.Digest)
for _, v := range versions {
txIds := make(map[string]*crypto.Digest)
tdslice := testdata.GetSameAliasNegativeDataMatrix(&suite.BaseSuite)
for _, td := range tdslice {
suite.Run(utl.GetTestcaseNameWithVersion(name, v), func() {
caseName := utl.GetTestcaseNameWithVersion(name, v)
suite.Run(caseName, func() {
//first alias tx should be successful
tx1, _, actualDiffBalanceInWaves1 := alias_utilities.BroadcastAliasTxAndGetWavesBalances(&suite.BaseSuite,
td, v, waitForTx)
utl.StatusCodesCheck(suite.T(), http.StatusOK, http.StatusOK, tx1, utl.GetTestcaseNameWithVersion(name, v))
errMsg := caseName + "Broadcast Alias Tx1: " + tx1.TxID.String()

addrByAliasGo, addrByAliasScala := utl.GetAddressesByAlias(&suite.BaseSuite, td.Alias)

utl.TxInfoCheck(suite.T(), tx1.WtErr.ErrWtGo, tx1.WtErr.ErrWtScala, utl.GetTestcaseNameWithVersion(name, v),
tx1.TxID.String())
utl.StatusCodesCheck(suite.T(), http.StatusOK, http.StatusOK, tx1, errMsg)
utl.TxInfoCheck(suite.T(), tx1.WtErr.ErrWtGo, tx1.WtErr.ErrWtScala, "Alias: "+tx1.TxID.String())
utl.AddressByAliasCheck(suite.T(), td.Expected.ExpectedAddressAfterFirstTx.Bytes(), addrByAliasGo,
addrByAliasScala)
addrByAliasScala, errMsg)
utl.WavesDiffBalanceCheck(suite.T(), td.Expected.WavesDiffBalanceAfterFirstTx,
actualDiffBalanceInWaves1.BalanceInWavesGo,
actualDiffBalanceInWaves1.BalanceInWavesScala, utl.GetTestcaseNameWithVersion(name, v))
actualDiffBalanceInWaves1.BalanceInWavesGo, actualDiffBalanceInWaves1.BalanceInWavesScala,
errMsg)

//second alias tx with same alias had same ID for v1 and v2
tx2, _, actualDiffBalanceInWaves2 := alias_utilities.BroadcastAliasTxAndGetWavesBalances(&suite.BaseSuite,
td, v, !waitForTx)
utl.StatusCodesCheck(suite.T(), http.StatusInternalServerError, http.StatusBadRequest, tx2,
utl.GetTestcaseNameWithVersion(name, v))
errMsg = caseName + "Broadcast Alias Tx2: " + tx2.TxID.String()
//already there for v1 and v2, and should be new for v3
txIds[name] = &tx2.TxID

utl.StatusCodesCheck(suite.T(), http.StatusInternalServerError, http.StatusBadRequest, tx2,
errMsg)
utl.ErrorMessageCheck(suite.T(), td.Expected.ErrBrdCstGoMsg, td.Expected.ErrBrdCstScalaMsg,
tx2.BrdCstErr.ErrorBrdCstGo, tx2.BrdCstErr.ErrorBrdCstScala, utl.GetTestcaseNameWithVersion(name, v))
tx2.BrdCstErr.ErrorBrdCstGo, tx2.BrdCstErr.ErrorBrdCstScala, errMsg)
utl.WavesDiffBalanceCheck(suite.T(), td.Expected.WavesDiffBalance, actualDiffBalanceInWaves2.BalanceInWavesGo,
actualDiffBalanceInWaves2.BalanceInWavesScala)
actualDiffBalanceInWaves2.BalanceInWavesScala, errMsg)
})
}
//should have same tx ID for Go and Scala v1 and v2
actualTxIds := utl.GetTxIdsInBlockchain(&suite.BaseSuite, txIds)
suite.Lenf(actualTxIds, idsCount, "IDs: %#v", actualTxIds, "Version:", v)
}
//should have same tx ID for Go and Scala v1 and v2
actualTxIds := utl.GetTxIdsInBlockchain(&suite.BaseSuite, txIds)
suite.Lenf(actualTxIds, 2, "IDs: %#v", actualTxIds)
}

func (suite *AliasTxApiSuite) Test_SameAliasDiffAddressesApiNegative() {
versions := alias_utilities.GetVersions(&suite.BaseSuite)
waitForTx := true
name := "Same alias for different accounts "
var idsCount = 2
txIds := make(map[string]*crypto.Digest)
for _, v := range versions {
tdSlice := testdata.GetSameAliasDiffAddressNegativeDataMatrix(&suite.BaseSuite)
txIds := make(map[string]*crypto.Digest)
suite.Run(utl.GetTestcaseNameWithVersion(name, v), func() {
caseName := utl.GetTestcaseNameWithVersion(name, v)
suite.Run(caseName, func() {
//send alias tx from account that is in first element of testdata slice
tx, _, actualDiffBalanceInWaves := alias_utilities.BroadcastAliasTxAndGetWavesBalances(&suite.BaseSuite,
tdSlice[0], v, waitForTx)
errMsg := caseName + "Broadcast Alias Tx: " + tx.TxID.String()

utl.StatusCodesCheck(suite.T(), http.StatusOK, http.StatusOK, tx, utl.GetTestcaseNameWithVersion(name, v))
utl.TxInfoCheck(suite.T(), tx.WtErr.ErrWtGo, tx.WtErr.ErrWtScala,
utl.GetTestcaseNameWithVersion(name, v), tx.TxID.String())
utl.StatusCodesCheck(suite.T(), http.StatusOK, http.StatusOK, tx, errMsg)
utl.TxInfoCheck(suite.T(), tx.WtErr.ErrWtGo, tx.WtErr.ErrWtScala, errMsg)
utl.WavesDiffBalanceCheck(suite.T(), tdSlice[0].Expected.WavesDiffBalanceAfterFirstTx,
actualDiffBalanceInWaves.BalanceInWavesGo, actualDiffBalanceInWaves.BalanceInWavesScala)
actualDiffBalanceInWaves.BalanceInWavesGo, actualDiffBalanceInWaves.BalanceInWavesScala,
errMsg)
//send alias tx from account that is in each next slice element
for j := 1; j < len(tdSlice); j++ {
tx, _, actualDiffBalanceInWaves := alias_utilities.BroadcastAliasTxAndGetWavesBalances(&suite.BaseSuite,
tdSlice[j], v, !waitForTx)
txIds[name] = &tx.TxID

utl.StatusCodesCheck(suite.T(), http.StatusInternalServerError, http.StatusBadRequest, tx,
utl.GetTestcaseNameWithVersion(name, v))

errMsg)
utl.WavesDiffBalanceCheck(suite.T(), tdSlice[j].Expected.WavesDiffBalance,
actualDiffBalanceInWaves.BalanceInWavesGo, actualDiffBalanceInWaves.BalanceInWavesGo)
actualDiffBalanceInWaves.BalanceInWavesGo, actualDiffBalanceInWaves.BalanceInWavesGo,
errMsg)
//because of new IDs for v3
if v == 3 {
idsCount = 0
utl.ErrorMessageCheck(suite.T(), tdSlice[j].Expected.ErrBrdCstGoMsg, tdSlice[j].Expected.ErrBrdCstScalaMsg,
tx.BrdCstErr.ErrorBrdCstGo, tx.BrdCstErr.ErrorBrdCstScala, utl.GetTestcaseNameWithVersion(name, v))
tx.BrdCstErr.ErrorBrdCstGo, tx.BrdCstErr.ErrorBrdCstScala,
errMsg)
}
}
})
actualTxIds := utl.GetTxIdsInBlockchain(&suite.BaseSuite, txIds)
suite.Lenf(actualTxIds, idsCount, "IDs: %#v", actualTxIds, "Version: %#v", v)
}
actualTxIds := utl.GetTxIdsInBlockchain(&suite.BaseSuite, txIds)
suite.Lenf(actualTxIds, idsCount, "IDs: %#v", actualTxIds)
}

func TestAliasTxApiSuite(t *testing.T) {
Expand Down
Loading

0 comments on commit e53aedd

Please sign in to comment.