Skip to content

Commit

Permalink
Merge pull request #351 from multiversx/new-price-aggregator-2024.10.04
Browse files Browse the repository at this point in the history
Integrated new contracts 2024.10.04
  • Loading branch information
iulianpascalau authored Oct 4, 2024
2 parents 7ddfdf8 + 6d36769 commit 5e47bc9
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
)

const (
timeout = time.Minute * 15
timeout = time.Minute * 15
projectedShardForTestKeys = byte(2)
)

func TestRelayersShouldExecuteTransfers(t *testing.T) {
Expand Down Expand Up @@ -369,7 +370,7 @@ func testEthContractsShouldError(tb testing.TB, testToken framework.TestTokenPar
valueToMintOnEth, ok := big.NewInt(0).SetString(testToken.ValueToMintOnEth, 10)
require.True(tb, ok)

receiverKeys := framework.GenerateMvxPrivatePublicKey(tb)
receiverKeys := framework.GenerateMvxPrivatePublicKey(tb, projectedShardForTestKeys)
auth, _ := bind.NewKeyedTransactorWithChainID(setup.DepositorKeys.EthSK, setup.EthereumHandler.ChainID)
_, err := setup.EthereumHandler.SafeContract.Deposit(auth, token.EthErc20Address, valueToMintOnEth, receiverKeys.MvxAddress.AddressSlice())
require.Error(tb, err)
Expand Down
51 changes: 34 additions & 17 deletions integrationTests/relayers/slowTests/framework/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
mxCrypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/stretchr/testify/require"
)

// constants for the keys store
const (
relayerPemPathFormat = "multiversx%d.pem"
SCCallerFilename = "scCaller.pem"
relayerPemPathFormat = "multiversx%d.pem"
SCCallerFilename = "scCaller.pem"
projectedShardForBridgeSetup = byte(0)
projectedShardForDepositor = byte(1)
projectedShardForTestKeys = byte(2)
)

// KeysHolder holds a 2 pk-sk pairs for both chains
Expand Down Expand Up @@ -63,14 +67,14 @@ func NewKeysStore(
}

keysStore.generateRelayersKeys(numRelayers)
keysStore.OraclesKeys = keysStore.generateKeys(numOracles, "generated oracle")
keysStore.SCExecutorKeys = keysStore.generateKey("")
keysStore.OwnerKeys = keysStore.generateKey(ethOwnerSK)
keysStore.OraclesKeys = keysStore.generateKeys(numOracles, "generated oracle", projectedShardForBridgeSetup)
keysStore.SCExecutorKeys = keysStore.generateKey("", projectedShardForBridgeSetup)
keysStore.OwnerKeys = keysStore.generateKey(ethOwnerSK, projectedShardForBridgeSetup)
log.Info("generated owner",
"MvX address", keysStore.OwnerKeys.MvxAddress.Bech32(),
"Eth address", keysStore.OwnerKeys.EthAddress.String())
keysStore.DepositorKeys = keysStore.generateKey(ethDepositorSK)
keysStore.TestKeys = keysStore.generateKey(ethTestSk)
keysStore.DepositorKeys = keysStore.generateKey(ethDepositorSK, projectedShardForDepositor)
keysStore.TestKeys = keysStore.generateKey(ethTestSk, projectedShardForTestKeys)

filename := path.Join(keysStore.workingDir, SCCallerFilename)
SaveMvxKey(keysStore, filename, keysStore.SCExecutorKeys)
Expand All @@ -83,7 +87,7 @@ func (keyStore *KeysStore) generateRelayersKeys(numKeys int) {
relayerETHSKBytes, err := os.ReadFile(fmt.Sprintf(relayerETHKeyPathFormat, i))
require.Nil(keyStore, err)

relayerKeys := keyStore.generateKey(string(relayerETHSKBytes))
relayerKeys := keyStore.generateKey(string(relayerETHSKBytes), projectedShardForBridgeSetup)
log.Info("generated relayer", "index", i,
"MvX address", relayerKeys.MvxAddress.Bech32(),
"Eth address", relayerKeys.EthAddress.String())
Expand All @@ -96,14 +100,14 @@ func (keyStore *KeysStore) generateRelayersKeys(numKeys int) {
}
}

func (keyStore *KeysStore) generateKeys(numKeys int, message string) []KeysHolder {
func (keyStore *KeysStore) generateKeys(numKeys int, message string, projectedShard byte) []KeysHolder {
keys := make([]KeysHolder, 0, numKeys)

for i := 0; i < numKeys; i++ {
ethPrivateKeyBytes := make([]byte, 32)
_, _ = rand.Read(ethPrivateKeyBytes)

key := keyStore.generateKey(hex.EncodeToString(ethPrivateKeyBytes))
key := keyStore.generateKey(hex.EncodeToString(ethPrivateKeyBytes), projectedShard)
log.Info(message, "index", i,
"MvX address", key.MvxAddress.Bech32(),
"Eth address", key.EthAddress.String())
Expand All @@ -114,10 +118,10 @@ func (keyStore *KeysStore) generateKeys(numKeys int, message string) []KeysHolde
return keys
}

func (keyStore *KeysStore) generateKey(ethSkHex string) KeysHolder {
func (keyStore *KeysStore) generateKey(ethSkHex string, projectedShard byte) KeysHolder {
var err error

keys := GenerateMvxPrivatePublicKey(keyStore)
keys := GenerateMvxPrivatePublicKey(keyStore, projectedShard)
if len(ethSkHex) == 0 {
// eth keys not required
return keys
Expand Down Expand Up @@ -169,21 +173,34 @@ func (keyStore *KeysStore) WalletsToFundOnMultiversX() []string {
}

// GenerateMvxPrivatePublicKey will generate a new keys holder instance that will hold only the MultiversX generated keys
func GenerateMvxPrivatePublicKey(tb testing.TB) KeysHolder {
sk, pk := keyGenerator.GeneratePair()
func GenerateMvxPrivatePublicKey(tb testing.TB, projectedShard byte) KeysHolder {
sk, pkBytes := generateSkPkInShard(tb, projectedShard)

skBytes, err := sk.ToByteArray()
require.Nil(tb, err)

pkBytes, err := pk.ToByteArray()
require.Nil(tb, err)

return KeysHolder{
MvxSk: skBytes,
MvxAddress: NewMvxAddressFromBytes(tb, pkBytes),
}
}

func generateSkPkInShard(tb testing.TB, projectedShard byte) (mxCrypto.PrivateKey, []byte) {
var sk mxCrypto.PrivateKey
var pk mxCrypto.PublicKey

for {
sk, pk = keyGenerator.GeneratePair()

pkBytes, err := pk.ToByteArray()
require.Nil(tb, err)

if pkBytes[len(pkBytes)-1] == projectedShard {
return sk, pkBytes
}
}
}

// SaveMvxKey will save the MultiversX key
func SaveMvxKey(tb testing.TB, filename string, key KeysHolder) {
blk := pem.Block{
Expand Down
Binary file modified integrationTests/relayers/slowTests/testdata/contracts/mvx/bridge-proxy.wasm
100755 → 100644
Binary file not shown.
Binary file modified integrationTests/relayers/slowTests/testdata/contracts/mvx/bridged-tokens-wrapper.wasm
100755 → 100644
Binary file not shown.
Binary file modified integrationTests/relayers/slowTests/testdata/contracts/mvx/esdt-safe.wasm
100755 → 100644
Binary file not shown.
Binary file modified integrationTests/relayers/slowTests/testdata/contracts/mvx/multi-transfer-esdt.wasm
100755 → 100644
Binary file not shown.
Binary file modified integrationTests/relayers/slowTests/testdata/contracts/mvx/multisig.wasm
100755 → 100644
Binary file not shown.
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-361-g5e42362"
"gitVersion": "v0.45.2.1-reproducible-375-gda17d9d"
},
"framework": {
"name": "multiversx-sc",
Expand Down Expand Up @@ -48,6 +48,10 @@
],
"outputs": []
},
"upgradeConstructor": {
"inputs": [],
"outputs": []
},
"endpoints": [
{
"name": "changeAmounts",
Expand Down Expand Up @@ -376,20 +380,105 @@
"indexed": true
},
{
"name": "epoch",
"type": "u64",
"name": "round",
"type": "u32",
"indexed": true
},
{
"name": "new_round_event",
"type": "NewRoundEvent"
}
]
},
{
"identifier": "discard_submission",
"inputs": [
{
"name": "from",
"type": "bytes",
"indexed": true
},
{
"name": "to",
"type": "bytes",
"indexed": true
},
{
"name": "round",
"type": "u32",
"indexed": true
},
{
"name": "discard_submission_event",
"type": "DiscardSubmissionEvent"
}
]
},
{
"identifier": "discard_round",
"inputs": [
{
"name": "from",
"type": "bytes",
"indexed": true
},
{
"name": "to",
"type": "bytes",
"indexed": true
},
{
"name": "round",
"type": "u32",
"indexed": true
}
]
},
{
"identifier": "add_submission",
"inputs": [
{
"name": "from",
"type": "bytes",
"indexed": true
},
{
"name": "to",
"type": "bytes",
"indexed": true
},
{
"name": "round",
"type": "u32",
"indexed": true
},
{
"name": "price",
"type": "BigUint"
}
]
}
],
"esdtAttributes": [],
"hasCallback": false,
"types": {
"DiscardSubmissionEvent": {
"type": "struct",
"fields": [
{
"name": "submission_timestamp",
"type": "u64"
},
{
"name": "first_submission_timestamp",
"type": "u64"
},
{
"name": "has_caller_already_submitted",
"type": "bool"
}
]
},
"NewRoundEvent": {
"type": "struct",
"fields": [
Expand Down
Binary file not shown.
Binary file modified integrationTests/relayers/slowTests/testdata/contracts/mvx/test-caller.wasm
100755 → 100644
Binary file not shown.

0 comments on commit 5e47bc9

Please sign in to comment.