Skip to content

Commit

Permalink
Merge pull request #352 from multiversx/new-price-aggregator-2024.10.08
Browse files Browse the repository at this point in the history
New price-aggregator contract
  • Loading branch information
iulianpascalau authored Oct 8, 2024
2 parents 5e47bc9 + b332105 commit d93f4b1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ func (instance *chainSimulatorWrapper) DeploySC(ctx context.Context, wasmFilePat
Version: 1,
}

hash := instance.signAndSend(ctx, ownerSK, ftx)
txResult := instance.getTransactionResult(ctx, hash)
hash := instance.signAndSend(ctx, ownerSK, ftx, 1)
txResult := instance.GetTransactionResult(ctx, hash)

return NewMvxAddressFromBech32(instance.TB, txResult.Logs.Events[0].Address), hash, txResult
}

// GetTransactionResult tries to get a transaction result. It may wait a few blocks
func (instance *chainSimulatorWrapper) getTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork {
func (instance *chainSimulatorWrapper) GetTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork {
instance.GenerateBlocksUntilTxProcessed(ctx, hash)

txResult, err := instance.proxyInstance.GetTransactionInfoWithResults(ctx, hash)
Expand All @@ -170,6 +170,10 @@ func (instance *chainSimulatorWrapper) getTransactionResult(ctx context.Context,

// GenerateBlocks calls the chain simulator generate block endpoint
func (instance *chainSimulatorWrapper) GenerateBlocks(ctx context.Context, numBlocks int) {
if numBlocks <= 0 {
return
}

_, status, err := instance.clientWrapper.PostHTTP(ctx, fmt.Sprintf(generateBlocksEndpoint, numBlocks), nil)
if err != nil || status != http.StatusOK {
log.Error("error in chainSimulatorWrapper.GenerateBlocks", "error", err, "status", status)
Expand Down Expand Up @@ -197,15 +201,33 @@ func (instance *chainSimulatorWrapper) GenerateBlocksUntilTxProcessed(ctx contex

// ScCall will make the provided sc call
func (instance *chainSimulatorWrapper) ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork) {
return instance.SendTx(ctx, senderSK, contract, value, gasLimit, createTxData(function, parameters))
}

// ScCallWithoutGenerateBlocks will make the provided sc call and do not trigger the generate blocks command
func (instance *chainSimulatorWrapper) ScCallWithoutGenerateBlocks(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) string {
return instance.SendTxWithoutGenerateBlocks(ctx, senderSK, contract, value, gasLimit, createTxData(function, parameters))
}

func createTxData(function string, parameters []string) []byte {
params := []string{function}
params = append(params, parameters...)
txData := strings.Join(params, "@")

return instance.SendTx(ctx, senderSK, contract, value, gasLimit, []byte(txData))
return []byte(txData)
}

// SendTx will build and send a transaction
func (instance *chainSimulatorWrapper) SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork) {
hash := instance.SendTxWithoutGenerateBlocks(ctx, senderSK, receiver, value, gasLimit, dataField)
instance.GenerateBlocks(ctx, 1)
txResult := instance.GetTransactionResult(ctx, hash)

return hash, txResult
}

// SendTxWithoutGenerateBlocks will build and send a transaction and won't call the generate blocks command
func (instance *chainSimulatorWrapper) SendTxWithoutGenerateBlocks(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) string {
networkConfig, err := instance.proxyInstance.GetNetworkConfig(ctx)
require.Nil(instance, err)

Expand All @@ -225,10 +247,9 @@ func (instance *chainSimulatorWrapper) SendTx(ctx context.Context, senderSK []by
Version: 1,
}

hash := instance.signAndSend(ctx, senderSK, ftx)
txResult := instance.getTransactionResult(ctx, hash)
hash := instance.signAndSend(ctx, senderSK, ftx, 0)

return hash, txResult
return hash
}

// FundWallets sends funds to the provided addresses
Expand Down Expand Up @@ -300,7 +321,7 @@ func (instance *chainSimulatorWrapper) getNonce(ctx context.Context, bech32Addre
return account.Nonce, nil
}

func (instance *chainSimulatorWrapper) signAndSend(ctx context.Context, senderSK []byte, ftx *transaction.FrontendTransaction) string {
func (instance *chainSimulatorWrapper) signAndSend(ctx context.Context, senderSK []byte, ftx *transaction.FrontendTransaction, numBlocksToGenerate int) string {
sig, err := computeTransactionSignature(senderSK, ftx)
require.Nil(instance, err)

Expand All @@ -309,7 +330,7 @@ func (instance *chainSimulatorWrapper) signAndSend(ctx context.Context, senderSK
hash, err := instance.proxyInstance.SendTransaction(ctx, ftx)
require.Nil(instance, err)

instance.GenerateBlocks(ctx, 1)
instance.GenerateBlocks(ctx, numBlocksToGenerate)

return hash
}
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/relayers/slowTests/framework/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ type ChainSimulatorWrapper interface {
GetNetworkAddress() string
DeploySC(ctx context.Context, path string, ownerSK []byte, gasLimit uint64, extraParams []string) (*MvxAddress, string, *data.TransactionOnNetwork)
ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork)
ScCallWithoutGenerateBlocks(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) string
SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork)
SendTxWithoutGenerateBlocks(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) string
FundWallets(ctx context.Context, wallets []string)
GenerateBlocksUntilEpochReached(ctx context.Context, epoch uint32)
GenerateBlocks(ctx context.Context, numBlocks int)
GetESDTBalance(ctx context.Context, address *MvxAddress, token string) string
GetBlockchainTimeStamp(ctx context.Context) uint64
GetTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork
}

// EthereumBlockchainClient defines the operations supported by the Ethereum client
Expand Down
17 changes: 13 additions & 4 deletions integrationTests/relayers/slowTests/framework/multiversxHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,18 +810,25 @@ func (handler *MultiversxHandler) getTokenNameFromResult(txResult data.Transacti

// SubmitAggregatorBatch will submit the aggregator batch
func (handler *MultiversxHandler) SubmitAggregatorBatch(ctx context.Context, params IssueTokenParams) {
txHashes := make([]string, 0, len(handler.OraclesKeys))
for _, key := range handler.OraclesKeys {
handler.submitAggregatorBatchForKey(ctx, key, params)
hash := handler.submitAggregatorBatchForKey(ctx, key, params)
txHashes = append(txHashes, hash)
}

for _, hash := range txHashes {
txResult := handler.ChainSimulator.GetTransactionResult(ctx, hash)
log.Info("submit aggregator batch tx", "hash", hash, "status", txResult.Status)
}
}

func (handler *MultiversxHandler) submitAggregatorBatchForKey(ctx context.Context, key KeysHolder, params IssueTokenParams) {
func (handler *MultiversxHandler) submitAggregatorBatchForKey(ctx context.Context, key KeysHolder, params IssueTokenParams) string {
timestamp := handler.ChainSimulator.GetBlockchainTimeStamp(ctx)
require.Greater(handler, timestamp, uint64(0), "something went wrong and the chain simulator returned 0 for the current timestamp")

timestampAsBigInt := big.NewInt(0).SetUint64(timestamp)

hash, txResult := handler.ChainSimulator.ScCall(
hash := handler.ChainSimulator.ScCallWithoutGenerateBlocks(
ctx,
key.MvxSk,
handler.AggregatorAddress,
Expand All @@ -835,7 +842,9 @@ func (handler *MultiversxHandler) submitAggregatorBatchForKey(ctx context.Contex
hex.EncodeToString(feeInt.Bytes()),
fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific)})

log.Info("submit aggregator batch tx executed", "transaction hash", hash, "submitter", key.MvxAddress.Bech32(), "status", txResult.Status)
log.Info("submit aggregator batch tx sent", "transaction hash", hash, "submitter", key.MvxAddress.Bech32())

return hash
}

// CreateDepositsOnMultiversxForToken will send the deposit transactions on MultiversX returning how many tokens should be minted on Ethereum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"contractCrate": {
"name": "multiversx-price-aggregator-sc",
"version": "0.47.1",
"gitVersion": "v0.45.2.1-reproducible-375-gda17d9d"
"gitVersion": "v0.45.2.1-reproducible-378-ge72c201"
},
"framework": {
"name": "multiversx-sc",
Expand Down
Binary file not shown.

0 comments on commit d93f4b1

Please sign in to comment.