-
Notifications
You must be signed in to change notification settings - Fork 9
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
Mint burn tokens #266
Conversation
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.
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 { |
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.
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 |
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.
TODO will be implemented in next PR?
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.
Yes
builder := dataGetter.createDefaultVmQueryBuilder() | ||
builder.Function(getAccumulatedBurnedTokensFuncName).ArgBytes(token) | ||
|
||
return dataGetter.executeQueryUint64FromBuilder(ctx, builder) |
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.
I think uint64 can easily overflow if we deal with 18-digits tokens.
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.
ExecuteQueryReturningBigInt created
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.
no other comments
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.
only those from Iulian. He made a good review.
… 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) { |
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.
empty test
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.
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 { |
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.
bytes.Equal(b1, b2)
instead of this? or simply string(b1) == string(b2)
(which bytes.Equal also does)
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.
removed
assert.Equal(t, "0xc5b2c658f5fa236c598a6e7fbf7f21413dc42e2a41dd982eb772b30707cba2eb", hash) | ||
assert.Nil(t, err) | ||
assert.True(t, wasCalled) | ||
}) | ||
} | ||
|
||
func TestClient_CheckRequiredBalance(t *testing.T) { |
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.
t.Paralel() on the main test?
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.
added
clients/ethereum/client_test.go
Outdated
// TokenMintedBalances | ||
// WhitelistedTokensMintBurn |
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.
// TokenMintedBalances | |
// WhitelistedTokensMintBurn |
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.
removed
|
||
// TokenMintedBalances | ||
// WhitelistedTokensMintBurn | ||
func TestClient_TokenMintedBalances(t *testing.T) { |
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.
t.Paralel() on main test + subtests?
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.
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") |
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.
extract it globally and reuse the same expectedErr
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.
in other context expectedErr has other value
clients/ethereum/client_test.go
Outdated
args := createMockEthereumClientArgs() | ||
args.ClientWrapper = &bridgeTests.EthereumClientWrapperStub{ | ||
TokenMintedBalancesCalled: func(ctx context.Context, token common.Address) (*big.Int, error) { | ||
return big.NewInt(100), nil |
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.
extract providedBalance := big.NewInt(100)
and check against it at the end of the test
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.
done
}) | ||
} | ||
|
||
func TestClient_WhitelistedTokensMintBurn(t *testing.T) { |
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.
t.Parallel() on main and subtests?
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.
added
Nonces []*big.Int | ||
} | ||
|
||
func ExtractList(batch *clients.TransferBatch) (*ArgListsBatch, error) { |
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.
missing comment
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.
done
@@ -3,6 +3,7 @@ package ethmultiversx | |||
import ( | |||
"context" | |||
"fmt" | |||
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor" |
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.
go imports
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.
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 { |
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.
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?
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.
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
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.
ok, should work then
if !found { | ||
existing = big.NewInt(0) | ||
transfers[token] = existing | ||
if _, exists := cumulatedAmounts[token]; exists { |
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.
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])
}
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.
done 👍
@@ -4,6 +4,7 @@ import ( | |||
"context" | |||
"errors" | |||
"fmt" | |||
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor" |
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.
go imports
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.
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]) |
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.
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.
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.
assert.Equal used instead, also no need for extra convertion to string. good suggestion
bridges/ethMultiversX/interface.go
Outdated
@@ -2,6 +2,7 @@ package ethmultiversx | |||
|
|||
import ( | |||
"context" | |||
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor" |
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.
go imports
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.
done
clients/ethereum/client.go
Outdated
@@ -4,6 +4,7 @@ import ( | |||
"context" | |||
"crypto/ecdsa" | |||
"fmt" | |||
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor" |
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.
go imports
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.
done
clients/ethereum/client_test.go
Outdated
@@ -5,6 +5,7 @@ import ( | |||
"encoding/hex" | |||
"errors" | |||
"fmt" | |||
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor" |
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.
go imports
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.
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 |
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.
nil, err
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.
done
@@ -2,6 +2,7 @@ package bridge | |||
|
|||
import ( | |||
"context" | |||
"github.com/multiversx/mx-bridge-eth-go/core/batchProcessor" |
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.
go imports
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.
done
"github.com/multiversx/mx-bridge-eth-go/clients" | ||
"math/big" |
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.
go imports
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.
done
No description provided.