Skip to content

Commit

Permalink
updated tests with new proto types for state changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristure committed Sep 24, 2024
1 parent ea2cf1a commit 8ae48f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
15 changes: 8 additions & 7 deletions state/stateChanges/dataAnalysisCollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (

data "github.com/multiversx/mx-chain-core-go/data/stateChange"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/storage/mock"
"github.com/multiversx/mx-chain-go/testscommon/state"
"github.com/stretchr/testify/require"
)

func TestNewDataAnalysisCollector(t *testing.T) {
Expand Down Expand Up @@ -41,13 +42,13 @@ func TestDataAnalysisStateChangesCollector_AddStateChange(t *testing.T) {
require.Equal(t, 0, len(dsc.stateChanges))

dsc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
})
dsc.AddStateChange(&data.StateChange{
Type: "read",
Type: data.Read,
})
dsc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
})

require.Equal(t, 3, len(dsc.stateChanges))
Expand All @@ -66,7 +67,7 @@ func TestDataAnalysisStateChangesCollector_AddSaveAccountStateChange(t *testing.
nil,
&state.UserAccountStub{},
&data.StateChange{
Type: "saveAccount",
Type: data.Write,
Index: 2,
TxHash: []byte("txHash1"),
MainTrieKey: []byte("key1"),
Expand Down Expand Up @@ -102,7 +103,7 @@ func TestDataAnalysisStateChangesCollector_AddSaveAccountStateChange(t *testing.
&state.UserAccountStub{},
nil,
&data.StateChange{
Type: "saveAccount",
Type: data.Write,
Index: 2,
TxHash: []byte("txHash1"),
MainTrieKey: []byte("key1"),
Expand Down Expand Up @@ -162,7 +163,7 @@ func TestDataAnalysisStateChangesCollector_AddSaveAccountStateChange(t *testing.
},
},
&data.StateChange{
Type: "saveAccount",
Type: data.Write,
Index: 2,
TxHash: []byte("txHash1"),
MainTrieKey: []byte("key1"),
Expand Down
33 changes: 17 additions & 16 deletions state/stateChanges/writeCollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (

data "github.com/multiversx/mx-chain-core-go/data/stateChange"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-go/state"
"github.com/stretchr/testify/assert"

"github.com/multiversx/mx-chain-go/state"

"github.com/stretchr/testify/require"
)

func getDefaultStateChange() *data.StateChange {
return &data.StateChange{
Type: "write",
Type: data.Write,
}
}

Expand Down Expand Up @@ -52,7 +53,7 @@ func TestStateChangesCollector_GetStateChanges(t *testing.T) {
numStateChanges := 10
for i := 0; i < numStateChanges; i++ {
scc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
MainTrieKey: []byte(strconv.Itoa(i)),
})
}
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestStateChangesCollector_GetStateChanges(t *testing.T) {
numStateChanges := 10
for i := 0; i < numStateChanges; i++ {
scc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
MainTrieKey: []byte(strconv.Itoa(i)),
})
}
Expand All @@ -107,7 +108,7 @@ func TestStateChangesCollector_AddTxHashToCollectedStateChanges(t *testing.T) {
scc.AddTxHashToCollectedStateChanges([]byte("txHash0"), &transaction.Transaction{})

stateChange := &data.StateChange{
Type: "write",
Type: data.Write,
MainTrieKey: []byte("mainTrieKey"),
MainTrieVal: []byte("mainTrieVal"),
DataTrieChanges: []*data.DataTrieChange{{Key: []byte("dataTrieKey"), Val: []byte("dataTrieVal")}},
Expand Down Expand Up @@ -262,7 +263,7 @@ func TestStateChangesCollector_GetStateChangesForTx(t *testing.T) {
numStateChanges := 10
for i := 0; i < numStateChanges; i++ {
scc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
// distribute evenly based on parity of the index
TxHash: []byte(fmt.Sprintf("hash%d", i%2)),
})
Expand All @@ -277,20 +278,20 @@ func TestStateChangesCollector_GetStateChangesForTx(t *testing.T) {
require.Equal(t, stateChangesForTx, map[string]*data.StateChanges{
"hash0": {
[]*data.StateChange{
{Type: "write", TxHash: []byte("hash0")},
{Type: "write", TxHash: []byte("hash0")},
{Type: "write", TxHash: []byte("hash0")},
{Type: "write", TxHash: []byte("hash0")},
{Type: "write", TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
},
},
"hash1": {
[]*data.StateChange{
{Type: "write", TxHash: []byte("hash1")},
{Type: "write", TxHash: []byte("hash1")},
{Type: "write", TxHash: []byte("hash1")},
{Type: "write", TxHash: []byte("hash1")},
{Type: "write", TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
},
},
})
Expand Down

0 comments on commit 8ae48f7

Please sign in to comment.