Skip to content
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

Mint burn tokens #266

Merged
merged 11 commits into from
Dec 22, 2023
Merged

Conversation

dragos-rebegea
Copy link
Contributor

No description provided.

@dragos-rebegea dragos-rebegea changed the base branch from main to feat/mint-burn November 28, 2023 08:00
Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some linter issues that prevent the unit tests correct running:

cannot use &bridge.MultiversXClientStub{} (type *bridge.MultiversXClientStub) as type MultiversXClient in field value:

@@ -18,6 +19,14 @@ const splits = 10

const minRetries = 1

type ArgListsBatch struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comment on exported items

@@ -403,6 +412,7 @@ func (executor *bridgeExecutor) PerformActionOnMultiversX(ctx context.Context) e
return ErrNilBatch
}

// TODO: check mintBurn balances before performing the action
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO will be implemented in next PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

bridges/ethMultiversX/bridgeExecutor.go Outdated Show resolved Hide resolved
bridges/ethMultiversX/bridgeExecutor.go Outdated Show resolved Hide resolved
bridges/ethMultiversX/bridgeExecutor.go Outdated Show resolved Hide resolved
clients/ethereum/client.go Show resolved Hide resolved
clients/ethereum/client.go Show resolved Hide resolved
builder := dataGetter.createDefaultVmQueryBuilder()
builder.Function(getAccumulatedBurnedTokensFuncName).ArgBytes(token)

return dataGetter.executeQueryUint64FromBuilder(ctx, builder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think uint64 can easily overflow if we deal with 18-digits tokens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExecuteQueryReturningBigInt created

Copy link
Contributor

@sstanculeanu sstanculeanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no other comments

Copy link
Contributor

@sasurobert sasurobert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only those from Iulian. He made a good review.

@dragos-rebegea dragos-rebegea changed the base branch from feat/mint-burn to feat/native-esdts-bridging December 20, 2023 14:30
… mint-burn-tokens

# Conflicts:
#	cmd/bridge/config/config.toml
#	go.mod
#	go.sum
#	integrationTests/testscommon.go
@@ -1196,6 +1204,9 @@ func TestMultiversXToEthBridgeExecutor_PerformTransferOnEthereum(t *testing.T) {
})
}

func TestMultiversXToEthBridgeExecutor_checkAvailableTokens(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -1655,3 +1666,16 @@ func TestBridgeExecutor_ValidateBatch(t *testing.T) {
assert.True(t, result)
assert.True(t, validateBatchCalled)
}

// CompareBytes compares two byte slices and returns true if they are equal.
func CompareBytes(a, b []byte) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes.Equal(b1, b2) instead of this? or simply string(b1) == string(b2) (which bytes.Equal also does)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

assert.Equal(t, "0xc5b2c658f5fa236c598a6e7fbf7f21413dc42e2a41dd982eb772b30707cba2eb", hash)
assert.Nil(t, err)
assert.True(t, wasCalled)
})
}

func TestClient_CheckRequiredBalance(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Paralel() on the main test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Comment on lines 696 to 697
// TokenMintedBalances
// WhitelistedTokensMintBurn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TokenMintedBalances
// WhitelistedTokensMintBurn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


// TokenMintedBalances
// WhitelistedTokensMintBurn
func TestClient_TokenMintedBalances(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Paralel() on main test + subtests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

// WhitelistedTokensMintBurn
func TestClient_TokenMintedBalances(t *testing.T) {
t.Run("error while getting token minted balances", func(t *testing.T) {
expectedErr := errors.New("expected error")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract it globally and reuse the same expectedErr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other context expectedErr has other value

args := createMockEthereumClientArgs()
args.ClientWrapper = &bridgeTests.EthereumClientWrapperStub{
TokenMintedBalancesCalled: func(ctx context.Context, token common.Address) (*big.Int, error) {
return big.NewInt(100), nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract providedBalance := big.NewInt(100) and check against it at the end of the test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

})
}

func TestClient_WhitelistedTokensMintBurn(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Parallel() on main and subtests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Nonces []*big.Int
}

func ExtractList(batch *clients.TransferBatch) (*ArgListsBatch, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -3,6 +3,7 @@ package ethmultiversx
import (
"context"
"fmt"
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if mintedBalance.Cmp(burntBalanceBigInt) < 0 {
return fmt.Errorf("%w, minted: %s, burnt: %s for ERC20 token %s",
ErrMintBurnBalance, mintedBalance.String(), burntBalanceBigInt.String(), erc20Address.String())
if mintedBalance.Cmp(burntBalance) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this ok? When will the burn be completed? At the moment of transfer in the mvx safe contract or when the transfer is completed on eth side and marked as finished on mvx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the transfer is completed on eth side and marked as finished on mvx, thats why it should be equal at the moment of the batch execution

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, should work then

clients/ethereum/client.go Show resolved Hide resolved
if !found {
existing = big.NewInt(0)
transfers[token] = existing
if _, exists := cumulatedAmounts[token]; exists {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code reads worse in this changeset. How about this:

for i, token := range tokens {
    existingValue, exists := cumulatedAmounts[token]
    if exists {
        existingValue.Add(existingValue, amounts[i])
        continue
    }

    cumulatedAmounts[token] = amounts[i]
    uniqueTokens = append(uniqueTokens, token)
    uniqueConvertedTokens = append(uniqueConvertedTokens, convertedTokens[i])

}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assert.True(t, providedBatch == batch)
assert.True(t, providedBatch.ID == batchId)
for i := 0; i < len(providedBatch.Deposits); i++ {
assert.True(t, providedBatch.Deposits[i].Amount == batch.Amounts[i])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use assert.Equal instead of assert.True as they will be evaluated by value not pointer. Also, the test will show a clearer image of what is wrong with assert.Equal. Valid here and on all asserts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert.Equal used instead, also no need for extra convertion to string. good suggestion

@@ -2,6 +2,7 @@ package ethmultiversx

import (
"context"
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -4,6 +4,7 @@ import (
"context"
"crypto/ecdsa"
"fmt"
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -5,6 +5,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

func (dataGetter *mxClientDataGetter) ExecuteQueryReturningBigInt(ctx context.Context, request *data.VmValueRequest) (*big.Int, error) {
response, err := dataGetter.ExecuteQueryReturningBytes(ctx, request)
if err != nil {
return big.NewInt(0), err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil, err

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -2,6 +2,7 @@ package bridge

import (
"context"
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"github.com/multiversx/mx-bridge-eth-go/clients"
"math/big"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@iulianpascalau iulianpascalau merged commit 0267f24 into feat/native-esdts-bridging Dec 22, 2023
3 checks passed
@iulianpascalau iulianpascalau deleted the mint-burn-tokens branch December 22, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants