-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deep queries on metachain #5958
Changes from all commits
50937b8
0630e26
2e255a3
20eab64
752b58a
7eac8b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package api_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
@@ -448,5 +449,24 @@ func TestCreateApiResolver_createScQueryElement(t *testing.T) { | |
require.True(t, strings.Contains(strings.ToLower(err.Error()), "hasher")) | ||
require.Nil(t, scQueryService) | ||
}) | ||
} | ||
|
||
func TestCreateApiResolver_createBlockchainForScQuery(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("for metachain", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
apiBlockchain, err := api.CreateBlockchainForScQuery(core.MetachainShardId) | ||
require.NoError(t, err) | ||
require.Equal(t, "*blockchain.metaChain", fmt.Sprintf("%T", apiBlockchain)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}) | ||
|
||
t.Run("for shard", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
apiBlockchain, err := api.CreateBlockchainForScQuery(0) | ||
require.NoError(t, err) | ||
require.Equal(t, "*blockchain.blockChain", fmt.Sprintf("%T", apiBlockchain)) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package integrationTests | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/data/transaction" | ||
) | ||
|
||
// MiniNetwork is a mini network, useful for some integration tests | ||
type MiniNetwork struct { | ||
Round uint64 | ||
Nonce uint64 | ||
|
||
Nodes []*TestProcessorNode | ||
ShardNode *TestProcessorNode | ||
MetachainNode *TestProcessorNode | ||
Users map[string]*TestWalletAccount | ||
} | ||
|
||
// NewMiniNetwork creates a MiniNetwork | ||
func NewMiniNetwork() *MiniNetwork { | ||
n := &MiniNetwork{} | ||
|
||
nodes := CreateNodes( | ||
1, | ||
1, | ||
1, | ||
) | ||
|
||
n.Nodes = nodes | ||
n.ShardNode = nodes[0] | ||
n.MetachainNode = nodes[1] | ||
n.Users = make(map[string]*TestWalletAccount) | ||
|
||
return n | ||
} | ||
|
||
// Stop stops the mini network | ||
func (n *MiniNetwork) Stop() { | ||
n.ShardNode.Close() | ||
n.MetachainNode.Close() | ||
} | ||
|
||
// FundAccount funds an account | ||
func (n *MiniNetwork) FundAccount(address []byte, value *big.Int) { | ||
shard := n.MetachainNode.ShardCoordinator.ComputeId(address) | ||
|
||
if shard == n.MetachainNode.ShardCoordinator.SelfId() { | ||
MintAddress(n.MetachainNode.AccntState, address, value) | ||
} else { | ||
MintAddress(n.ShardNode.AccntState, address, value) | ||
} | ||
} | ||
|
||
// AddUser adds a user (account) to the mini network | ||
func (n *MiniNetwork) AddUser(balance *big.Int) *TestWalletAccount { | ||
user := CreateTestWalletAccount(n.ShardNode.ShardCoordinator, 0) | ||
n.Users[string(user.Address)] = user | ||
n.FundAccount(user.Address, balance) | ||
return user | ||
} | ||
|
||
// Start starts the mini network | ||
func (n *MiniNetwork) Start() { | ||
n.Round = 1 | ||
n.Nonce = 1 | ||
} | ||
|
||
// Continue advances processing with a number of rounds | ||
func (n *MiniNetwork) Continue(t *testing.T, numRounds int) { | ||
idxProposers := []int{0, 1} | ||
|
||
for i := int64(0); i < int64(numRounds); i++ { | ||
n.Nonce, n.Round = ProposeAndSyncOneBlock(t, n.Nodes, idxProposers, n.Round, n.Nonce) | ||
} | ||
} | ||
|
||
// SendTransaction sends a transaction | ||
func (n *MiniNetwork) SendTransaction( | ||
senderPubkey []byte, | ||
receiverPubkey []byte, | ||
value *big.Int, | ||
data string, | ||
additionalGasLimit uint64, | ||
) (string, error) { | ||
sender, ok := n.Users[string(senderPubkey)] | ||
if !ok { | ||
return "", fmt.Errorf("unknown sender: %s", hex.EncodeToString(senderPubkey)) | ||
} | ||
|
||
tx := &transaction.Transaction{ | ||
Nonce: sender.Nonce, | ||
Value: new(big.Int).Set(value), | ||
SndAddr: sender.Address, | ||
RcvAddr: receiverPubkey, | ||
Data: []byte(data), | ||
GasPrice: MinTxGasPrice, | ||
GasLimit: MinTxGasLimit + uint64(len(data)) + additionalGasLimit, | ||
ChainID: ChainID, | ||
Version: MinTransactionVersion, | ||
} | ||
|
||
txBuff, _ := tx.GetDataForSigning(TestAddressPubkeyConverter, TestTxSignMarshalizer, TestTxSignHasher) | ||
tx.Signature, _ = sender.SingleSigner.Sign(sender.SkTxSign, txBuff) | ||
txHash, err := n.ShardNode.SendTransaction(tx) | ||
|
||
sender.Nonce++ | ||
|
||
return txHash, err | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ type GasScheduleMap = map[string]map[string]uint64 | |
// TestNetwork wraps a set of TestProcessorNodes along with a set of test | ||
// Wallets, instantiates them, controls them and provides operations with them; | ||
// designed to be used in integration tests. | ||
// TODO combine TestNetwork with the preexisting TestContext and OneNodeNetwork | ||
// TODO combine TestNetwork with the preexisting TestContext and MiniNetwork | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only in the end I've seen that we have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can postpone |
||
// into a single struct containing the functionality of all three | ||
type TestNetwork struct { | ||
NumShards int | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very proud of this unit test.
Question for review: keep it or remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ok. I would keep the tests :D