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

Child chain mintable predicates E2E tests #1560

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ed4d27a
Simplify helper bridge commands
Stefan-Ethernal May 28, 2023
0dc0ea9
Prevent mapping childchain mintable native token on non-mintable pred…
Stefan-Ethernal May 28, 2023
5255ed5
Provide stake token address to rootchain deploy command
Stefan-Ethernal May 29, 2023
7493955
WIP
Stefan-Ethernal May 29, 2023
f4285bf
Revert not needed changes
Stefan-Ethernal May 29, 2023
326c9d6
Mintable native token bridge transfer E2E test
Stefan-Ethernal May 30, 2023
bbe0c57
Wrap up bridge native erc20 mintable e2e test
Stefan-Ethernal May 31, 2023
cc690f2
Update smart contracts spec
Stefan-Ethernal May 31, 2023
9899d64
Register bridge common flags at once
Stefan-Ethernal Jun 1, 2023
0d88fa1
Provide stake token address where missing
Stefan-Ethernal Jun 1, 2023
c6663f5
Fix E2E tests
Stefan-Ethernal Jun 1, 2023
35d5c2b
Remove isExitEventProcessed helper function
Stefan-Ethernal Jun 1, 2023
45fc03c
E2E tests for access list mintable predicates
Stefan-Ethernal Jun 1, 2023
08af539
ERC-721 tokens bridging E2E test WIP
Stefan-Ethernal Jun 1, 2023
bc64d83
Fix warnings
Stefan-Ethernal Jun 2, 2023
b881bd3
Decouple minter and sender key in deposit commands
Stefan-Ethernal Jun 2, 2023
960d337
Update README
Stefan-Ethernal Jun 2, 2023
1d91952
ERC-721 owner of helper function
Stefan-Ethernal Jun 2, 2023
0065ad9
Fix deposit commands
Stefan-Ethernal Jun 2, 2023
4602e6f
Update to the latest SC spec and remove not needed bindings
Stefan-Ethernal Jun 2, 2023
db1e8c4
Wrap up ERC721 tokens bridging E2E test
Stefan-Ethernal Jun 2, 2023
6c53e81
Fix unit test
Stefan-Ethernal Jun 2, 2023
ee6a002
Comment
Stefan-Ethernal Jun 2, 2023
a97504b
Comments
Stefan-Ethernal Jun 2, 2023
2a3d80c
Change exit event ids from string to big int in deposit and withdraw …
Stefan-Ethernal Jun 3, 2023
efbe858
Update to the latest SC spec
Stefan-Ethernal Jun 4, 2023
6601dfc
Fix race condition
Stefan-Ethernal Jun 5, 2023
0934855
Introduce buffered channel
Stefan-Ethernal Jun 5, 2023
b3f0edc
Consolidate bridge transaction result structs (#1584)
Stefan-Ethernal Jun 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy.nightly.devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ jobs:
polygon-edge rootchain deploy \
--deployer-key $(cat rootchain-wallet.json | jq -r '.HexPrivateKey') \
--stake-manager $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeManagerAddr') \
--stake-token $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeTokenAddr') \
--json-rpc {{ rootchain_json_rpc }}

{% for item in hostvars %}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test-e2e-polybft:
# We can not build with race because of a bug in boltdb dependency
go build -o artifacts/polygon-edge .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true \
go test -v -timeout=1h ./e2e-polybft/e2e/...
go test -v -timeout=1h10m ./e2e-polybft/e2e/...

.PHONY: test-property-polybft
test-property-polybft:
Expand Down
9 changes: 5 additions & 4 deletions command/bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ $ polygon-edge bridge deposit-erc20 \
--amounts <amounts> \
--root-token <root_erc20_token_address> \
--root-predicate <root_erc20_predicate_address> \
--json-rpc <root_chain_json_rpc_endpoint>
--json-rpc <json_rpc_endpoint>
[--minter-key <hex_encoded_minter_account_private_key>]
```

**Note:** for using test account provided by Geth dev instance, use `--test` flag. In that case `--sender-key` flag can be omitted and test account is used as a depositor.
**Note:** in case `minter-key` is provided, tokens are going to be minted to sender account. Note that provided minter private key must belong to the account which has minter role.

## Withdraw ERC20

Expand All @@ -27,9 +28,9 @@ $ polygon-edge bridge withdraw-erc20 \
--sender-key <hex_encoded_txn_sender_private_key> \
--receivers <receivers_addresses> \
--amounts <amounts> \
--child-predicate <rchild_erc20_predicate_address> \
--child-predicate <child_erc20_predicate_address> \
[--child-token <child_erc20_token_address>] \
--json-rpc <child_chain_json_rpc_endpoint>
--json-rpc <json_rpc_endpoint>
```

## Exit
Expand Down
157 changes: 142 additions & 15 deletions command/bridge/common/params.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
package common

import (
"bytes"
"errors"
"fmt"
"math/big"
"strings"

"github.com/spf13/cobra"
"github.com/umbracle/ethgo"

cmdHelper "github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/txrelayer"
)

type TokenType int
Expand All @@ -13,16 +24,20 @@ const (
)

const (
SenderKeyFlag = "sender-key"
ReceiversFlag = "receivers"
AmountsFlag = "amounts"
TokenIDsFlag = "token-ids"

RootTokenFlag = "root-token"
RootPredicateFlag = "root-predicate"
ChildPredicateFlag = "child-predicate"
ChildTokenFlag = "child-token"
JSONRPCFlag = "json-rpc"
SenderKeyFlag = "sender-key"
ReceiversFlag = "receivers"
AmountsFlag = "amounts"
TokenIDsFlag = "token-ids"
RootTokenFlag = "root-token"
RootPredicateFlag = "root-predicate"
ChildPredicateFlag = "child-predicate"
ChildTokenFlag = "child-token"
JSONRPCFlag = "json-rpc"
ChildChainMintableFlag = "child-chain-mintable"

MinterKeyFlag = "minter-key"
MinterKeyFlagDesc = "minter key is the account which is able to mint tokens to sender account " +
"(if provided tokens are minted prior to depositing)"
)

var (
Expand All @@ -31,11 +46,43 @@ var (
)

type BridgeParams struct {
SenderKey string
Receivers []string
TokenAddr string
PredicateAddr string
JSONRPCAddr string
SenderKey string
Receivers []string
TokenAddr string
PredicateAddr string
JSONRPCAddr string
ChildChainMintable bool
}

// RegisterCommonFlags registers common bridge flags to a given command
func (p *BridgeParams) RegisterCommonFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
&p.SenderKey,
SenderKeyFlag,
"",
"hex encoded private key of the account which sends bridge transactions",
)

cmd.Flags().StringSliceVar(
&p.Receivers,
ReceiversFlag,
nil,
"receiving accounts addresses",
)

cmd.Flags().StringVar(
&p.JSONRPCAddr,
JSONRPCFlag,
txrelayer.DefaultRPCAddress,
"the JSON RPC endpoint",
)

cmd.Flags().BoolVar(
&p.ChildChainMintable,
ChildChainMintableFlag,
false,
"flag indicating whether tokens originate from child chain",
)
}

type ERC20BridgeParams struct {
Expand Down Expand Up @@ -93,3 +140,83 @@ func (bp *ERC1155BridgeParams) Validate() error {

return nil
}

// ExtractExitEventID tries to extract exit event id from provided receipt
func ExtractExitEventID(receipt *ethgo.Receipt) (*big.Int, error) {
var exitEvent contractsapi.L2StateSyncedEvent
for _, log := range receipt.Logs {
doesMatch, err := exitEvent.ParseLog(log)
if err != nil {
return nil, err
}

if !doesMatch {
continue
}

return exitEvent.ID, nil
}

return nil, errors.New("failed to find exit event log")
}

type BridgeTxResult struct {
Sender string `json:"sender"`
Receivers []string `json:"receivers"`
ExitEventIDs []*big.Int `json:"exitEventIDs"`
Amounts []string `json:"amounts"`
TokenIDs []string `json:"tokenIds"`
BlockNumbers []uint64 `json:"blockNumbers"`

Title string `json:"title"`
}

func (r *BridgeTxResult) GetOutput() string {
var buffer bytes.Buffer

vals := make([]string, 0, 5)
vals = append(vals, fmt.Sprintf("Sender|%s", r.Sender))
vals = append(vals, fmt.Sprintf("Receivers|%s", strings.Join(r.Receivers, ", ")))

if len(r.Amounts) > 0 {
vals = append(vals, fmt.Sprintf("Amounts|%s", strings.Join(r.Amounts, ", ")))
}

if len(r.TokenIDs) > 0 {
vals = append(vals, fmt.Sprintf("Token Ids|%s", strings.Join(r.TokenIDs, ", ")))
}

if len(r.ExitEventIDs) > 0 {
var buf bytes.Buffer

for i, id := range r.ExitEventIDs {
buf.WriteString(id.String())

if i != len(r.ExitEventIDs)-1 {
buf.WriteString(", ")
}
}

vals = append(vals, fmt.Sprintf("Exit Event IDs|%s", buf.String()))
}

if len(r.BlockNumbers) > 0 {
var buf bytes.Buffer

for i, blockNum := range r.BlockNumbers {
buf.WriteString(fmt.Sprintf("%d", blockNum))

if i != len(r.BlockNumbers)-1 {
buf.WriteString(", ")
}
}

vals = append(vals, fmt.Sprintf("Inclusion Block Numbers|%s", buf.String()))
}

_, _ = buffer.WriteString(fmt.Sprintf("\n[%s]\n", r.Title))
_, _ = buffer.WriteString(cmdHelper.FormatKV(vals))
_, _ = buffer.WriteString("\n")

return buffer.String()
}
Loading