diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..a1e0f8e1 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,28 @@ +name: Release prod docker image +on: + push: + branches: [release-prod] + +jobs: + docker-release: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout peggo + uses: actions/checkout@master + with: + repository: InjectiveLabs/peggo + ref: release-prod + token: ${{ secrets.GH_TOKEN }} + path: ./peggo + - name: Build image + run: | + cd peggo + docker build -t public.ecr.aws/l9h3g6c6/peggo:prod . + - name: Push image + run: | + aws configure set aws_access_key_id ${{ secrets.AWS_KEY }} + aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET }} + aws configure set region us-east-1 + aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/l9h3g6c6 + docker push public.ecr.aws/l9h3g6c6/peggo:prod diff --git a/cmd/peggo/orchestrator.go b/cmd/peggo/orchestrator.go index d4eed5d1..e7d5cd77 100644 --- a/cmd/peggo/orchestrator.go +++ b/cmd/peggo/orchestrator.go @@ -154,7 +154,7 @@ func orchestratorCmd(cmd *cli.Cmd) { peggo, err := orchestrator.NewOrchestrator( cosmosNetwork, ethNetwork, - pricefeed.NewCoingeckoPriceFeed(100, &pricefeed.Config{BaseURL: *cfg.coingeckoApi}), + pricefeed.NewDummyCoingeckoFeed(), orchestratorCfg, ) orShutdown(err) diff --git a/orchestrator/pricefeed/dummy_coingecko.go b/orchestrator/pricefeed/dummy_coingecko.go new file mode 100644 index 00000000..a7575286 --- /dev/null +++ b/orchestrator/pricefeed/dummy_coingecko.go @@ -0,0 +1,28 @@ +package pricefeed + +import ( + "errors" + "github.com/ethereum/go-ethereum/common" +) + +type DummyCoingeckoFeed struct { + tokens map[string]string // token_addr -> denom +} + +func NewDummyCoingeckoFeed() DummyCoingeckoFeed { + return DummyCoingeckoFeed{ + tokens: map[string]string{ + "0x7E5C521F8515017487750c13C3bF3B15f3f5f654": "inj", + "0x1ccec198630F2024c64C0aFC5aE2427bc8e2dce8": "wut", + }, + } +} + +func (f DummyCoingeckoFeed) QueryUSDPrice(address common.Address) (float64, error) { + switch f.tokens[address.Hex()] { + case "inj", "wut": + return 10, nil + default: + return 0, errors.New("unknown token") + } +} diff --git a/solidity/wrappers/CosmosToken.sol/wrapper.go b/solidity/wrappers/CosmosToken.sol/wrapper.go index c6e29871..c194085b 100644 --- a/solidity/wrappers/CosmosToken.sol/wrapper.go +++ b/solidity/wrappers/CosmosToken.sol/wrapper.go @@ -33,7 +33,7 @@ const ContextABI = "[]" type Context struct { ContextCaller // Read-only binding to the contract ContextTransactor // Write-only binding to the contract - ContextFilterer // Log filterer for contract events + ContextFilterer // log filterer for contract events } // ContextCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -210,7 +210,7 @@ func DeployCosmosERC20(auth *bind.TransactOpts, backend bind.ContractBackend, pe type CosmosERC20 struct { CosmosERC20Caller // Read-only binding to the contract CosmosERC20Transactor // Write-only binding to the contract - CosmosERC20Filterer // Log filterer for contract events + CosmosERC20Filterer // log filterer for contract events } // CosmosERC20Caller is an auto generated read-only Go binding around an Ethereum contract. @@ -646,7 +646,7 @@ type CosmosERC20ApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -800,7 +800,7 @@ type CosmosERC20TransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -986,7 +986,7 @@ func DeployERC20(auth *bind.TransactOpts, backend bind.ContractBackend, name_ st type ERC20 struct { ERC20Caller // Read-only binding to the contract ERC20Transactor // Write-only binding to the contract - ERC20Filterer // Log filterer for contract events + ERC20Filterer // log filterer for contract events } // ERC20Caller is an auto generated read-only Go binding around an Ethereum contract. @@ -1422,7 +1422,7 @@ type ERC20ApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -1576,7 +1576,7 @@ type ERC20TransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -1740,7 +1740,7 @@ var IERC20FuncSigs = map[string]string{ type IERC20 struct { IERC20Caller // Read-only binding to the contract IERC20Transactor // Write-only binding to the contract - IERC20Filterer // Log filterer for contract events + IERC20Filterer // log filterer for contract events } // IERC20Caller is an auto generated read-only Go binding around an Ethereum contract. @@ -2041,7 +2041,7 @@ type IERC20ApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -2195,7 +2195,7 @@ type IERC20TransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -2362,7 +2362,7 @@ var IERC20MetadataFuncSigs = map[string]string{ type IERC20Metadata struct { IERC20MetadataCaller // Read-only binding to the contract IERC20MetadataTransactor // Write-only binding to the contract - IERC20MetadataFilterer // Log filterer for contract events + IERC20MetadataFilterer // log filterer for contract events } // IERC20MetadataCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -2756,7 +2756,7 @@ type IERC20MetadataApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -2910,7 +2910,7 @@ type IERC20MetadataTransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration diff --git a/solidity/wrappers/HashingTest.sol/wrapper.go b/solidity/wrappers/HashingTest.sol/wrapper.go index 7432287e..94d3f710 100644 --- a/solidity/wrappers/HashingTest.sol/wrapper.go +++ b/solidity/wrappers/HashingTest.sol/wrapper.go @@ -63,7 +63,7 @@ func DeployHashingTest(auth *bind.TransactOpts, backend bind.ContractBackend) (c type HashingTest struct { HashingTestCaller // Read-only binding to the contract HashingTestTransactor // Write-only binding to the contract - HashingTestFilterer // Log filterer for contract events + HashingTestFilterer // log filterer for contract events } // HashingTestCaller is an auto generated read-only Go binding around an Ethereum contract. diff --git a/solidity/wrappers/Peggy.sol/wrapper.go b/solidity/wrappers/Peggy.sol/wrapper.go index 39adbf4b..159251b8 100644 --- a/solidity/wrappers/Peggy.sol/wrapper.go +++ b/solidity/wrappers/Peggy.sol/wrapper.go @@ -59,7 +59,7 @@ func DeployAddress(auth *bind.TransactOpts, backend bind.ContractBackend) (commo type Address struct { AddressCaller // Read-only binding to the contract AddressTransactor // Write-only binding to the contract - AddressFilterer // Log filterer for contract events + AddressFilterer // log filterer for contract events } // AddressCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -204,7 +204,7 @@ const ContextABI = "[]" type Context struct { ContextCaller // Read-only binding to the contract ContextTransactor // Write-only binding to the contract - ContextFilterer // Log filterer for contract events + ContextFilterer // log filterer for contract events } // ContextCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -349,7 +349,7 @@ const ContextUpgradeableABI = "[]" type ContextUpgradeable struct { ContextUpgradeableCaller // Read-only binding to the contract ContextUpgradeableTransactor // Write-only binding to the contract - ContextUpgradeableFilterer // Log filterer for contract events + ContextUpgradeableFilterer // log filterer for contract events } // ContextUpgradeableCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -526,7 +526,7 @@ func DeployCosmosERC20(auth *bind.TransactOpts, backend bind.ContractBackend, pe type CosmosERC20 struct { CosmosERC20Caller // Read-only binding to the contract CosmosERC20Transactor // Write-only binding to the contract - CosmosERC20Filterer // Log filterer for contract events + CosmosERC20Filterer // log filterer for contract events } // CosmosERC20Caller is an auto generated read-only Go binding around an Ethereum contract. @@ -962,7 +962,7 @@ type CosmosERC20ApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -1116,7 +1116,7 @@ type CosmosERC20TransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -1302,7 +1302,7 @@ func DeployERC20(auth *bind.TransactOpts, backend bind.ContractBackend, name_ st type ERC20 struct { ERC20Caller // Read-only binding to the contract ERC20Transactor // Write-only binding to the contract - ERC20Filterer // Log filterer for contract events + ERC20Filterer // log filterer for contract events } // ERC20Caller is an auto generated read-only Go binding around an Ethereum contract. @@ -1738,7 +1738,7 @@ type ERC20ApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -1892,7 +1892,7 @@ type ERC20TransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -2056,7 +2056,7 @@ var IERC20FuncSigs = map[string]string{ type IERC20 struct { IERC20Caller // Read-only binding to the contract IERC20Transactor // Write-only binding to the contract - IERC20Filterer // Log filterer for contract events + IERC20Filterer // log filterer for contract events } // IERC20Caller is an auto generated read-only Go binding around an Ethereum contract. @@ -2357,7 +2357,7 @@ type IERC20ApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -2511,7 +2511,7 @@ type IERC20TransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -2678,7 +2678,7 @@ var IERC20MetadataFuncSigs = map[string]string{ type IERC20Metadata struct { IERC20MetadataCaller // Read-only binding to the contract IERC20MetadataTransactor // Write-only binding to the contract - IERC20MetadataFilterer // Log filterer for contract events + IERC20MetadataFilterer // log filterer for contract events } // IERC20MetadataCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -3072,7 +3072,7 @@ type IERC20MetadataApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -3226,7 +3226,7 @@ type IERC20MetadataTransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -3380,7 +3380,7 @@ const InitializableABI = "[]" type Initializable struct { InitializableCaller // Read-only binding to the contract InitializableTransactor // Write-only binding to the contract - InitializableFilterer // Log filterer for contract events + InitializableFilterer // log filterer for contract events } // InitializableCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -3535,7 +3535,7 @@ var OwnableUpgradeableWithExpiryFuncSigs = map[string]string{ type OwnableUpgradeableWithExpiry struct { OwnableUpgradeableWithExpiryCaller // Read-only binding to the contract OwnableUpgradeableWithExpiryTransactor // Write-only binding to the contract - OwnableUpgradeableWithExpiryFilterer // Log filterer for contract events + OwnableUpgradeableWithExpiryFilterer // log filterer for contract events } // OwnableUpgradeableWithExpiryCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -3836,7 +3836,7 @@ type OwnableUpgradeableWithExpiryOwnershipTransferredIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -3994,7 +3994,7 @@ var PausableFuncSigs = map[string]string{ type Pausable struct { PausableCaller // Read-only binding to the contract PausableTransactor // Write-only binding to the contract - PausableFilterer // Log filterer for contract events + PausableFilterer // log filterer for contract events } // PausableCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -4170,7 +4170,7 @@ type PausablePausedIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -4304,7 +4304,7 @@ type PausableUnpausedIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -4481,7 +4481,7 @@ func DeployPeggy(auth *bind.TransactOpts, backend bind.ContractBackend) (common. type Peggy struct { PeggyCaller // Read-only binding to the contract PeggyTransactor // Write-only binding to the contract - PeggyFilterer // Log filterer for contract events + PeggyFilterer // log filterer for contract events } // PeggyCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -5208,7 +5208,7 @@ type PeggyERC20DeployedEventIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -5357,7 +5357,7 @@ type PeggyOwnershipTransferredIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -5510,7 +5510,7 @@ type PeggyPausedIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -5644,7 +5644,7 @@ type PeggySendToCosmosEventIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -5808,7 +5808,7 @@ type PeggySendToInjectiveEventIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -5973,7 +5973,7 @@ type PeggyTransactionBatchExecutedEventIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -6127,7 +6127,7 @@ type PeggyUnpausedIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -6261,7 +6261,7 @@ type PeggyValsetUpdatedEventIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -6410,7 +6410,7 @@ const ReentrancyGuardABI = "[]" type ReentrancyGuard struct { ReentrancyGuardCaller // Read-only binding to the contract ReentrancyGuardTransactor // Write-only binding to the contract - ReentrancyGuardFilterer // Log filterer for contract events + ReentrancyGuardFilterer // log filterer for contract events } // ReentrancyGuardCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -6572,7 +6572,7 @@ func DeploySafeERC20(auth *bind.TransactOpts, backend bind.ContractBackend) (com type SafeERC20 struct { SafeERC20Caller // Read-only binding to the contract SafeERC20Transactor // Write-only binding to the contract - SafeERC20Filterer // Log filterer for contract events + SafeERC20Filterer // log filterer for contract events } // SafeERC20Caller is an auto generated read-only Go binding around an Ethereum contract. diff --git a/solidity/wrappers/TestERC20.sol/wrapper.go b/solidity/wrappers/TestERC20.sol/wrapper.go index c12dafe5..003b0b54 100644 --- a/solidity/wrappers/TestERC20.sol/wrapper.go +++ b/solidity/wrappers/TestERC20.sol/wrapper.go @@ -33,7 +33,7 @@ const ContextABI = "[]" type Context struct { ContextCaller // Read-only binding to the contract ContextTransactor // Write-only binding to the contract - ContextFilterer // Log filterer for contract events + ContextFilterer // log filterer for contract events } // ContextCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -210,7 +210,7 @@ func DeployERC20(auth *bind.TransactOpts, backend bind.ContractBackend, name_ st type ERC20 struct { ERC20Caller // Read-only binding to the contract ERC20Transactor // Write-only binding to the contract - ERC20Filterer // Log filterer for contract events + ERC20Filterer // log filterer for contract events } // ERC20Caller is an auto generated read-only Go binding around an Ethereum contract. @@ -646,7 +646,7 @@ type ERC20ApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -800,7 +800,7 @@ type ERC20TransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -964,7 +964,7 @@ var IERC20FuncSigs = map[string]string{ type IERC20 struct { IERC20Caller // Read-only binding to the contract IERC20Transactor // Write-only binding to the contract - IERC20Filterer // Log filterer for contract events + IERC20Filterer // log filterer for contract events } // IERC20Caller is an auto generated read-only Go binding around an Ethereum contract. @@ -1265,7 +1265,7 @@ type IERC20ApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -1419,7 +1419,7 @@ type IERC20TransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -1586,7 +1586,7 @@ var IERC20MetadataFuncSigs = map[string]string{ type IERC20Metadata struct { IERC20MetadataCaller // Read-only binding to the contract IERC20MetadataTransactor // Write-only binding to the contract - IERC20MetadataFilterer // Log filterer for contract events + IERC20MetadataFilterer // log filterer for contract events } // IERC20MetadataCaller is an auto generated read-only Go binding around an Ethereum contract. @@ -1980,7 +1980,7 @@ type IERC20MetadataApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -2134,7 +2134,7 @@ type IERC20MetadataTransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -2320,7 +2320,7 @@ func DeployTestERC20(auth *bind.TransactOpts, backend bind.ContractBackend) (com type TestERC20 struct { TestERC20Caller // Read-only binding to the contract TestERC20Transactor // Write-only binding to the contract - TestERC20Filterer // Log filterer for contract events + TestERC20Filterer // log filterer for contract events } // TestERC20Caller is an auto generated read-only Go binding around an Ethereum contract. @@ -2756,7 +2756,7 @@ type TestERC20ApprovalIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration @@ -2910,7 +2910,7 @@ type TestERC20TransferIterator struct { contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data - logs chan types.Log // Log channel receiving the found contract events + logs chan types.Log // log channel receiving the found contract events sub ethereum.Subscription // Subscription for errors, completion and termination done bool // Whether the subscription completed delivering logs fail error // Occurred error to stop iteration diff --git a/test/README.md b/test/README.md index efc26c57..68fa27af 100644 --- a/test/README.md +++ b/test/README.md @@ -1,144 +1,41 @@ ## Peggo Testsuite +[IN PROGRESS] + Welcome to the PegGo testing framework. The goal of this suite is aligned with the overall project goal - to move stuff onto common ground and iterate faster. By using the same lang for module, orchestrator and test we can achieve the full test coverage of all logical branches. -This is a special place where we don't care about things like: -* Node version -* Myriads of JS packages complaining about versions and API inconsistencies -* Different locations of ERC20 contract artifacts -* Stuff being deployed slowly -* Debugging ganache bugs - -We care about: -* Speed of the full run -* Go code coverage reports -* Zero issues coming from tooling or dev env -* Cross-platformity (macOS youKnow) -* Supporting any target EVM that implements Ethereum JSON-RPC -* 100% compatibility with real network - -## Prerequisites - -You can specify any remote EVM endpoint to run the test against, but the best and most stable way to test the stuff is to run a Ganache or Hardhat instance. Hardhat is used solely as a JSON-RPC node provider. - -Preferred Solc compiler toolkit: -* https://github.com/crytic/solc-select - -Run `solc-select use 0.8.2` before starting any tests. - -### Running with Hardhat - -Hardhat is a newer alternative to Ganache that has convenient initialization via the config file. - -Running the init script will install node_modules inside `./test/ethereum` dir. - -``` -$ ./test/ethereum/hardhat-init.sh -``` - -After init is done, the following command can be used to launch a Hardhat server instance: - -``` -$ ./test/ethereum/hardhat.sh -``` - -The only option that can be set via ENV variable: +To set up the testing env, just run `test/run.sh` The script initializes 3 Injective validator nodes and 1 geth instance to simulate Injective and Ethereum networks respectively. After the networks are started 3 Peggo orchestrators are run for each of the validator nodes. +For simplicity, the script runs with hardcoded values for most of the configurations. Tweaking parameters is not yet supported. -* `HARDHAT_PORT` - specify the port for server to listen on. Defaults to `8545`. +The script `test/run.sh` can be run multiple times. On each run it removes all previously written files with new ones. +Before running the script again, make sure you've killed all the injectived/geth processes (e.g. `killall injectived`). -The rest of the options can be tweaked via `./test/ethereum/hardhat.config.js` - -### Pre-prod testing with Geth - -In order to get maximum compatibility with the real blockchain environment and avoid any bugs in the EVM runtime of Hardhat/Ganache, -also check different blocktime conditions, one might want to run Geth itself. - -Running this script will init a persistent data storage for the private network. - -``` -$ ./test/ethereum/geth-init.sh -``` - -Init options can be set via ENV variables: - -* `GETH_NETWORK_ID` - specify Ethereum Network ID, defaults to `50`. -* `GETH_ALGO` - specify the consensus algorith for block producing. Defaults to `clique` (PoA), but `ethash` (PoW) is supported too. Make sure you adjust difficulty by patching your Geth (see at the bottom of this page) -* `CHAIN_DIR` - specify the data dir, a prefix for all data dirs and logs. Defaults to `./data` - -Chain options can be tweaked in `./test/ethereum/geth/genesis.json` - -After init is done, the following command can be used to launch a full Geth node instance: - -``` -$ ./test/ethereum/geth.sh -``` - -Running options can be set via ENV variables: +## Prerequisites -* `GETH_NETWORK_ID` - specify Ethereum Network ID, defaults to `50`. -* `GETH_ALGO` - specify the consensus algorith for block producing. Defaults to `ethash` (PoW), but `clique` (PoA) supported. -* `GETH_PORT` - specify the port for server to listen on. Defaults to `8545`. -* `CHAIN_DIR` - specify the data dir, a prefix for all data dirs and logs. Defaults to `./data` +- `injective-core`: run `make install` on the `fix/peggy-contract-redeployment` branch +- `geth`: version 1.13.10-stable +- `etherman`: from https://github.com/InjectiveLabs/etherman/ +- `jq` +- `tmux` +- `perl` +- `sed` -### Cosmos Daemon -This testsuite supports different Cosmos backends, basically any app that has `peggy` module built-in will do. We expect that the generic app is Cosmos-SDK compatible and has very similar CLI interface to `gaiad`. There is a script that would launch an isolated full 3-node network, running natively on the host machine. Just make sure to provide the target executable as an argument. +### Injective -> Ethereum flow -``` -$ CHAIN_ID=888 DENOM=inj ./test/cosmos/multinode.sh injectived -$ CHAIN_ID=somm DENOM=samoleans STAKE_DENOM=stake SCALE_FACTOR=000000 ./test/cosmos/multinode.sh sommelier -``` +- To send some `inj` tokens to Ethereum, run `test/send_to_eth.sh`. +- To send a cosmos native token other than `inj`, the `test/deploy_token.sh` deploys a new "WAT" token on Ethereum. Afterward, tweak the `test/send_to_eth.sh` to send the new token (already premined during `test/run.sh`) -Full list of the supported ENV variables: -* `CHAIN_ID` - specifies Cosmos Chain ID, like `peggy-1` -* `CHAIN_DIR` - is a prefix for all data dirs and logs, will be removed if `CLEANUP=1` -* `DENOM` - Cosmos coin denom, the default coin of the network. Examples: `uatom`, `aphoton`, `samoleans` etc -* `STAKE_DENOM` - Cosmos coin denom that is used for staking and governance. On the Cosmos Hub it's `stake`. Defaults to value of `DENOM` in the script. -* `SCALE_FACTOR` - Scale factor for the Cosmos coin. Defaults to 1e18 to reflect Ethereum token balances. Use `000000` to follow Cosmos uatom (1e6) style. -* `CLEANUP` - if this option set to `1`, then the `CHAIN_DIR` will be removed in the most unsafe manner. -* `LOG_LEVEL` - sets the log level of the Cosmos node configuration. Defaults to Cosmos' default (`main:info,state:info,statesync:info,*:error`). +### Ethereum -> Injective flow -**Important**: it is safe to run the script multiple times, it will stop nodes upon running, and optionally cleanup the state. If the state is not empty, the script will start nodes without running initialization again. So it could be used for manually retriable tests. +- To send some `inj` tokens to Ethereum, run `test/send_to_inj.sh` +- Other tokens: TODO ### Cosmos Accounts The script imports 3 validator accounts and 1 user account, specified by mnemonics in the script itself. Each validator account accessible as `val` on the corresponding nodes, and user account is shared across all three nodes as `user`. -### Misc: Patching Geth - -Geth by default scales difficulty of the blocks to hit the target block pace. So even if your network starts with `difficulty=1` in genesis, the difficulty will be higher in the next blocks and waiting times would be very high. Especially that DAG regeneration phases. A solution to this in local setup would be to either use `clique` consensus for PoA-style block producing, or just patch the Geth code, so the difficulty won't grow. - -Just clone the `go-ethereum` repo, apply this patch: - -```diff -diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go -index bdc02098a..c17ea5b76 100644 ---- a/consensus/ethash/consensus.go -+++ b/consensus/ethash/consensus.go -@@ -315,19 +315,7 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time uin - // the difficulty that a new block should have when created at time - // given the parent block's time and difficulty. - func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int { -- next := new(big.Int).Add(parent.Number, big1) -- switch { -- case config.IsMuirGlacier(next): -- return calcDifficultyEip2384(time, parent) -- case config.IsConstantinople(next): -- return calcDifficultyConstantinople(time, parent) -- case config.IsByzantium(next): -- return calcDifficultyByzantium(time, parent) -- case config.IsHomestead(next): -- return calcDifficultyHomestead(time, parent) -- default: -- return calcDifficultyFrontier(time, parent) -- } -+ return big1 - } -``` - -And install it with `go install ./cmd/geth`. Welcome to the Geth forking! - ## Contributing Patches and suggestions are welcome. We're looking for better coverage and maybe some isolated benchmarks. diff --git a/test/blacklist_eth.sh b/test/blacklist_eth.sh new file mode 100755 index 00000000..26aa2b1b --- /dev/null +++ b/test/blacklist_eth.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +cd "${0%/*}" # cd in the script dir + +passphrase=12345678 +tx_opts="--chain-id=injective-333 --gas-prices 500000000inj --keyring-backend test --broadcast-mode=sync --yes --home /Users/dbrajovic/Desktop/dev/Injective/peggo/test/cosmos/data/injective-333/n0 --from user" + +# Send INJ tokens +yes $passphrase | injectived tx peggy blacklist-ethereum-addresses "0xBbDf3283d1Cf510c17B4FfA1b900F444bE4A4A4e" $tx_opts + diff --git a/test/cosmos/multinode.sh b/test/cosmos/multinode.sh index 9e3debda..3d142356 100755 --- a/test/cosmos/multinode.sh +++ b/test/cosmos/multinode.sh @@ -7,27 +7,32 @@ set -e +cd "${0%/*}" # cd to current script dir + CWD=$(pwd) # These options can be overridden by env -CHAIN_ID="${CHAIN_ID:-888}" +CHAIN_ID="${CHAIN_ID:-"injective-333"}" CHAIN_DIR="${CHAIN_DIR:-$CWD/data}" -DENOM="${DENOM:-uatom}" +DENOM="${DENOM:-inj}" STAKE_DENOM="${STAKE_DENOM:-$DENOM}" CLEANUP="${CLEANUP:-0}" LOG_LEVEL="${LOG_LEVEL:-main:info,state:info,statesync:info,*:error}" SCALE_FACTOR="${SCALE_FACTOR:-000000000000000000}" +NEWLINE=$'\n' # Default 3 account keys + 1 user key with no special grants VAL0_KEY="val" VAL0_MNEMONIC="copper push brief egg scan entry inform record adjust fossil boss egg comic alien upon aspect dry avoid interest fury window hint race symptom" + VAL1_KEY="val" VAL1_MNEMONIC="maximum display century economy unlock van census kite error heart snow filter midnight usage egg venture cash kick motor survey drastic edge muffin visual" + VAL2_KEY="val" VAL2_MNEMONIC="keep liar demand upon shed essence tip undo eagle run people strong sense another salute double peasant egg royal hair report winner student diamond" + USER_KEY="user" USER_MNEMONIC="pony glide frown crisp unfold lawn cup loan trial govern usual matrix theory wash fresh address pioneer between meadow visa buffalo keep gallery swear" -NEWLINE=$'\n' hdir="$CHAIN_DIR/$CHAIN_ID" @@ -44,26 +49,11 @@ then exit 1 fi -# Expect Chain ID to be provided -if [[ -z "$CHAIN_ID" ]]; then - echo "Please provide Cosmos CHAIN_ID env" - exit 1 -fi - -# Expect data prefix to be provided -if [[ -z "$CHAIN_DIR" ]]; then - echo "Please provide CHAIN_DIR data prefix" - exit 1 -fi - NODE_BIN="$1" -echo "Using $CHAIN_ID as Chain ID and $CHAIN_DIR as data prefix." -echo "Using $DENOM as Cosmos Coin Denom." if [[ "$CLEANUP" == 1 || "$CLEANUP" == "1" ]]; then echo "Will remove $CHAIN_DIR" fi -echo "Press ^C if you don't agree.." killall "$NODE_BIN" &>/dev/null || true @@ -104,7 +94,7 @@ cid="--chain-id $CHAIN_ID" # Check if the data dir has been initialized already if [[ ! -d "$hdir" ]]; then - echo "Creating 3x $NODE_BIN validators with chain-id=$CHAIN_ID" + echo "Creating 3x $NODE_BIN validators and 1 user account..." # Build genesis file and create accounts if [[ "$STAKE_DENOM" != "$DENOM" ]]; then @@ -114,8 +104,6 @@ if [[ ! -d "$hdir" ]]; then fi coins_user="1000000$SCALE_FACTOR$DENOM" - echo "initializing node homes..." - # Initialize the home directories of each node $NODE_BIN $home0 $cid init n0 &>/dev/null $NODE_BIN $home1 $cid init n1 &>/dev/null @@ -135,10 +123,10 @@ if [[ ! -d "$hdir" ]]; then yes "$USER_MNEMONIC$NEWLINE" | $NODE_BIN $home2 keys add $USER_KEY $kbt --recover &>/dev/null # Add addresses to genesis - $NODE_BIN $home0 add-genesis-account $($NODE_BIN $home0 keys show $VAL0_KEY -a $kbt) $coins &>/dev/null - $NODE_BIN $home0 add-genesis-account $($NODE_BIN $home1 keys show $VAL1_KEY -a $kbt) $coins &>/dev/null - $NODE_BIN $home0 add-genesis-account $($NODE_BIN $home2 keys show $VAL2_KEY -a $kbt) $coins &>/dev/null - $NODE_BIN $home0 add-genesis-account $($NODE_BIN $home0 keys show $USER_KEY -a $kbt) $coins_user &>/dev/null + $NODE_BIN $home0 $cid add-genesis-account $($NODE_BIN $home0 keys show $VAL0_KEY -a $kbt) $coins + $NODE_BIN $home0 $cid add-genesis-account $($NODE_BIN $home1 keys show $VAL1_KEY -a $kbt) $coins &>/dev/null + $NODE_BIN $home0 $cid add-genesis-account $($NODE_BIN $home2 keys show $VAL2_KEY -a $kbt) $coins &>/dev/null + $NODE_BIN $home0 $cid add-genesis-account $($NODE_BIN $home0 keys show $USER_KEY -a $kbt) $coins_user &>/dev/null # Patch genesis.json to better configure stuff for testing purposes if [[ "$STAKE_DENOM" == "$DENOM" ]]; then @@ -146,38 +134,83 @@ if [[ ! -d "$hdir" ]]; then cat $n0cfgDir/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="'$DENOM'"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json cat $n0cfgDir/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="'$DENOM'"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json cat $n0cfgDir/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json + cat $n0cfgDir/genesis.json | jq '.app_state["gov"]["params"]["min_deposit"][0]["denom"]="'$DENOM'"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json fi echo "NOTE: Setting Governance Voting Period to 10 seconds for rapid testing" cat $n0cfgDir/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="10s"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json + cat $n0cfgDir/genesis.json | jq '.app_state["gov"]["params"]["voting_period"]="10s"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json + cat $n0cfgDir/genesis.json | jq '.app_state["gov"]["params"]["expedited_voting_period"]="9s"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json + + + + # Mint Watever tokens for each validator + jq '.app_state.bank.supply += [ + { + "denom": "wut", + "amount": "16000000000000000000000000" + } + ]' $n0cfgDir/genesis.json > tmp_file && mv tmp_file $n0cfgDir/genesis.json + + jq '.app_state.bank.balances |= map(.coins += [ + { + "denom": "wut", + "amount": "4000000000000000000000000" + } + ])' $n0cfgDir/genesis.json > tmp_file && mv tmp_file $n0cfgDir/genesis.json + + jq '.app_state.bank.denom_metadata += [ + { + "description": "Some token I made for testing the bridge", + "denom_units": [ + { + "denom": "wut", + "exponent": 0, + "aliases": [] + }, + { + "denom": "wat", + "exponent": 18, + "aliases": [] + } + ], + "base": "wut", + "display": "wat", + "name": "Watever", + "symbol": "wat", + "uri": "", + "uri_hash": "" + } + ]' $n0cfgDir/genesis.json > tmp_file && mv tmp_file $n0cfgDir/genesis.json + # Copy genesis around to sign cp $n0cfgDir/genesis.json $n1cfgDir/genesis.json cp $n0cfgDir/genesis.json $n2cfgDir/genesis.json # Create gentxs and collect them in n0 - $NODE_BIN $home0 gentx $VAL0_KEY --amount=1000$SCALE_FACTOR$STAKE_DENOM $kbt $cid &>/dev/null - $NODE_BIN $home1 gentx $VAL1_KEY --amount=1000$SCALE_FACTOR$STAKE_DENOM $kbt $cid &>/dev/null - $NODE_BIN $home2 gentx $VAL2_KEY --amount=1000$SCALE_FACTOR$STAKE_DENOM $kbt $cid &>/dev/null + $NODE_BIN $home0 genesis gentx $VAL0_KEY "1000$SCALE_FACTOR$STAKE_DENOM" $kbt $cid + $NODE_BIN $home1 genesis gentx $VAL1_KEY "1000$SCALE_FACTOR$STAKE_DENOM" $kbt $cid &>/dev/null + $NODE_BIN $home2 genesis gentx $VAL2_KEY "1000$SCALE_FACTOR$STAKE_DENOM" $kbt $cid &>/dev/null cp $n1cfgDir/gentx/*.json $n0cfgDir/gentx/ cp $n2cfgDir/gentx/*.json $n0cfgDir/gentx/ - $NODE_BIN $home0 collect-gentxs &>/dev/null + $NODE_BIN $home0 genesis collect-gentxs &>/dev/null # Copy genesis file into n1 and n2s cp $n0cfgDir/genesis.json $n1cfgDir/genesis.json cp $n0cfgDir/genesis.json $n2cfgDir/genesis.json # Run this to ensure everything worked and that the genesis file is setup correctly - $NODE_BIN $home0 validate-genesis - $NODE_BIN $home1 validate-genesis - $NODE_BIN $home2 validate-genesis + $NODE_BIN $home0 genesis validate + $NODE_BIN $home1 genesis validate + $NODE_BIN $home2 genesis validate # Actually a cross-platform solution, sed is rubbish # Example usage: $REGEX_REPLACE 's/^param = ".*?"/param = "100"/' config.toml REGEX_REPLACE="perl -i -pe" - echo "regex replacing config variables" + echo "Regex replacing config variables" $REGEX_REPLACE 's|addr_book_strict = true|addr_book_strict = false|g' $n0cfg $REGEX_REPLACE 's|external_address = ""|external_address = "tcp://127.0.0.1:26657"|g' $n0cfg @@ -217,33 +250,30 @@ if [[ ! -d "$hdir" ]]; then $REGEX_REPLACE 's|persistent_peers = ""|persistent_peers = "'$peer1','$peer2'"|g' $n0cfg $REGEX_REPLACE 's|persistent_peers = ""|persistent_peers = "'$peer0','$peer2'"|g' $n1cfg $REGEX_REPLACE 's|persistent_peers = ""|persistent_peers = "'$peer0','$peer1'"|g' $n2cfg + fi # data dir check # Start the instances -echo "Starting nodes..." +echo "Starting validator nodes..." -echo $NODE_BIN $home0 start --grpc.address="0.0.0.0:9090" +echo $NODE_BIN $home0 start --grpc.address "0.0.0.0:9090" +$NODE_BIN $home0 start --grpc.address "0.0.0.0:9090" > $hdir.n0.log 2>&1 & -$NODE_BIN $home0 start --grpc.address="0.0.0.0:9090" > $hdir.n0.log 2>&1 & -$NODE_BIN $home1 start --grpc.address="0.0.0.0:9091" > $hdir.n1.log 2>&1 & -$NODE_BIN $home2 start --grpc.address="0.0.0.0:9092" > $hdir.n2.log 2>&1 & +echo $NODE_BIN $home1 start --grpc.address "0.0.0.0:9091" +$NODE_BIN $home1 start --grpc.address "0.0.0.0:9091" > $hdir.n1.log 2>&1 & + +echo $NODE_BIN $home2 start --grpc.address "0.0.0.0:9092" +$NODE_BIN $home2 start --grpc.address "0.0.0.0:9092" > $hdir.n2.log 2>&1 & # Wait for chains to start -echo "Waiting for chains to start..." -sleep 8 +sleep 5 echo echo "Logs:" -echo " * tail -f ./data/$CHAIN_ID.n0.log" -echo " * tail -f ./data/$CHAIN_ID.n1.log" -echo " * tail -f ./data/$CHAIN_ID.n2.log" -echo -echo "Env for easy access:" -echo "export H1='--home ./data/$CHAIN_ID/n0/'" -echo "export H2='--home ./data/$CHAIN_ID/n1/'" -echo "export H3='--home ./data/$CHAIN_ID/n2/'" +echo " tail -f ./data/$CHAIN_ID.n0.log" +echo " tail -f ./data/$CHAIN_ID.n1.log" +echo " tail -f ./data/$CHAIN_ID.n2.log" echo -echo "Command Line Access:" -echo " * $NODE_BIN --home ./data/$CHAIN_ID/n0 status" -echo " * $NODE_BIN --home ./data/$CHAIN_ID/n1 status" -echo " * $NODE_BIN --home ./data/$CHAIN_ID/n2 status" \ No newline at end of file +echo "Injective network setup complete!" +echo + diff --git a/test/deploy_token.sh b/test/deploy_token.sh new file mode 100755 index 00000000..c1c48502 --- /dev/null +++ b/test/deploy_token.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +cd "${0%/*}" # cd in the script dir + +deployer_pk=$(cat ./ethereum/geth/clique_signer.key) +peggy_contract="../solidity/contracts/Peggy.sol" +peggy_contract_address=0x5048019d259217e6b7BC8e1E6aEfa9976B1ADFfe + +etherman --name Peggy --source "$peggy_contract" -P "$deployer_pk" tx "$peggy_contract_address" deployERC20 "wut" "wat" "wat" 18 diff --git a/test/ethereum/geth-init.sh b/test/ethereum/geth-init.sh index 4cdab0dc..d4c2a1b9 100755 --- a/test/ethereum/geth-init.sh +++ b/test/ethereum/geth-init.sh @@ -2,24 +2,26 @@ set -e +cd "${0%/*}" # cd to current script dir + CWD=$(pwd) # These options can be overridden by env GETH_NETWORK_ID="${GETH_NETWORK_ID:-50}" -GETH_ALGO="${GETH_ALGO:-ethash}" +GETH_ALGO="${GETH_ALGO:-clique}" CHAIN_DIR="${CHAIN_DIR:-$CWD/data}" -hdir="$CHAIN_DIR/$GETH_NETWORK_ID" -ddir="--datadir $hdir" +if [[ $GETH_ALGO != "clique" ]]; then + echo "Unsupported geth algo: $GETH_ALGO. Must use clique" + exit 1 +fi + +DATA_DIR="$CHAIN_DIR/$GETH_NETWORK_ID" -cd "${0%/*}" # cd to current script dir +# Initialize geth dir and setup account +geth init --datadir "$DATA_DIR" ./geth/clique_genesis.json +geth account import --datadir "$DATA_DIR" --lightkdf --password ./geth/clique_password.txt ./geth/clique_signer.key -if [[ $GETH_ALGO == "ethash" ]]; then - geth init $ddir ./geth/genesis.json -elif [[ $GETH_ALGO == "clique" ]]; then - geth init $ddir ./geth/clique_genesis.json - geth account import $ddir --lightkdf --password ./geth/clique_password.txt ./geth/clique_signer.key -else - echo "Unsupported Geth algo: $GETH_ALGO, use ethash or clique" - exit 1 -fi +# Create PID and log file +touch "$CHAIN_DIR/$GETH_NETWORK_ID.geth.pid" +touch "$CHAIN_DIR/$GETH_NETWORK_ID.geth.log" \ No newline at end of file diff --git a/test/ethereum/geth.sh b/test/ethereum/geth.sh index ac7ad4a7..83f07ee2 100755 --- a/test/ethereum/geth.sh +++ b/test/ethereum/geth.sh @@ -2,51 +2,50 @@ set -e +cd "${0%/*}" # cd to current script dir + CWD=$(pwd) # These options can be overridden by env GETH_PORT="${GETH_PORT:-8545}" GETH_NETWORK_ID="${GETH_NETWORK_ID:-50}" -GETH_ALGO="${GETH_ALGO:-ethash}" +GETH_ALGO="${GETH_ALGO:-clique}" GETH_BLOCK_GAS_LIMIT="${GETH_BLOCK_GAS_LIMIT:-60000000}" CHAIN_DIR="${CHAIN_DIR:-$CWD/data}" +MINER_ADDR="0xBbDf3283d1Cf510c17B4FfA1b900F444bE4A4A4e" -hdir="$CHAIN_DIR/$GETH_NETWORK_ID" -mkdir -p $hdir +DATA_DIR="$CHAIN_DIR/$GETH_NETWORK_ID" -# killall geth -kill $(cat $hdir.geth.pid) &>/dev/null && rm $hdir.geth.pid || true +if [[ $GETH_ALGO != "clique" ]]; then + echo "Unsupported geth algo: $GETH_ALGO. Must use clique" + exit 1 +fi + +# Kill the node if it's already running +pid="$(cat "$DATA_DIR.geth.pid")" +if kill "$pid" &>/dev/null; then + rm "$DATA_DIR.geth.pid" +fi sleep 1 -cd "${0%/*}" # cd to current script dir +# Start the local geth node +geth --datadir "$DATA_DIR" --networkid "$GETH_NETWORK_ID" --nodiscover \ + --http --http.port "$GETH_PORT" --http.api personal,eth,net,web3 --allow-insecure-unlock \ + --miner.etherbase $MINER_ADDR --unlock $MINER_ADDR --password ./geth/clique_password.txt \ + --mine --miner.gaslimit "$GETH_BLOCK_GAS_LIMIT" > "$DATA_DIR".geth.log 2>&1 & -if [[ $GETH_ALGO == "ethash" ]]; then - geth --datadir $hdir --networkid $GETH_NETWORK_ID --nodiscover \ - --http --http.port $GETH_PORT --http.api personal,eth,net,web3 \ - --miner.threads=1 --etherbase=0xBbDf3283d1Cf510c17B4FfA1b900F444bE4A4A4e \ - --mine --targetgaslimit $GETH_BLOCK_GAS_LIMIT > $hdir.geth.log 2>&1 & - echo $! > $hdir.geth.pid -elif [[ $GETH_ALGO == "clique" ]]; then - geth --datadir $hdir --networkid $GETH_NETWORK_ID --nodiscover \ - --http --http.port $GETH_PORT --http.api personal,eth,net,web3 --allow-insecure-unlock \ - --unlock 0xBbDf3283d1Cf510c17B4FfA1b900F444bE4A4A4e --password ./geth/clique_password.txt \ - --mine --targetgaslimit $GETH_BLOCK_GAS_LIMIT > $hdir.geth.log 2>&1 & - echo $! > $hdir.geth.pid -else - echo "Unsupported Geth algo: $GETH_ALGO, use ethash or clique" - exit 1 -fi +echo $! > "$DATA_DIR".geth.pid # overwrite previous PID +PID=$(cat ./data/$GETH_NETWORK_ID.geth.pid) sleep 1 -echo +echo "Geth:" +echo " http://localhost:$GETH_PORT" echo "Logs:" echo " tail -f ./data/$GETH_NETWORK_ID.geth.log" -echo -echo "Command Line Access:" -echo " geth attach http://localhost:8545" -echo " geth attach ./data/$GETH_NETWORK_ID/geth.ipc" -echo echo "Shutdown:" -echo " kill \$(cat ./data/$GETH_NETWORK_ID.geth.pid)" +echo " kill $PID" +echo +echo "Ethereum network setup complete!" +echo \ No newline at end of file diff --git a/test/ethereum/geth/clique_genesis.json b/test/ethereum/geth/clique_genesis.json index 825399fd..5c9d9c84 100644 --- a/test/ethereum/geth/clique_genesis.json +++ b/test/ethereum/geth/clique_genesis.json @@ -21,7 +21,7 @@ "difficulty": "1", "alloc": { "0xBbDf3283d1Cf510c17B4FfA1b900F444bE4A4A4e": { - "balance": "0x1" + "balance": "0x6bc75e2d63100000" }, "0x5409ED021D9299bf6814279A6A1411A7e866A631": { "balance": "0x6bc75e2d63100000" @@ -52,6 +52,18 @@ }, "0x91c987bf62D25945dB517BDAa840A6c661374402": { "balance": "0x6bc75e2d63100000" + }, + + "0x4e9feE2BCdf6F21b17b77BD0ac9faDD6fF16B4d4": { + "balance": "0x6bc75e2d63100000" + }, + + "0xec43B0eA83844Cbe5A20F5371604BD452Cb1012c": { + "balance": "0x6bc75e2d63100000" + }, + + "0x8B094eD440900CEB75B83A22eD8A2C7582B442C2": { + "balance": "0x6bc75e2d63100000" } } } \ No newline at end of file diff --git a/test/peggo/deploy_peggy_contract_suite.sh b/test/peggo/deploy_peggy_contract_suite.sh new file mode 100755 index 00000000..2c291c99 --- /dev/null +++ b/test/peggo/deploy_peggy_contract_suite.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +set -e + +cd "${0%/*}" # cd in the script dir + +# get the bridge_contract_start_height early so orchestrators can catch the first Valset Updated event from Peggy.sol +peggy_block_number=$(curl http://localhost:8545 \ + -X POST \ + -H "Content-Type: application/json" \ + -d '{"id":1,"jsonrpc":"2.0", "method":"eth_getBlockByNumber","params":["latest", true]}' 2>/dev/null \ + | python3 -c "import sys, json; print(int(json.load(sys.stdin)['result']['number'], 0))") + + +# Initial Validator Set on Injective +PEGGY_ID="${PEGGY_ID:-0x696e6a6563746976652d70656767796964000000000000000000000000000000}" # bytes32 encoding of "injective-peggyid" +POWER_THRESHOLD="${POWER_THRESHOLD:-1431655765}" # how to get: 2/3 of total validator power on Injective + +VALIDATOR_ADDRESSES="${VALIDATOR_ADDRESSES:-\ +0x4e9feE2BCdf6F21b17b77BD0ac9faDD6fF16B4d4,\ +0xec43B0eA83844Cbe5A20F5371604BD452Cb1012c,\ +0x8B094eD440900CEB75B83A22eD8A2C7582B442C2}" + +VALIDATOR_POWERS="${VALIDATOR_POWERS:-\ +1431655765,\ +1431655765,\ +1431655765}" + +PEGGY_INIT_ARGS="$PEGGY_ID $POWER_THRESHOLD $VALIDATOR_ADDRESSES $VALIDATOR_POWERS" + +# Peggy contracts +PEGGY_CONTRACT_PATH="../../solidity/contracts/Peggy.sol" +PROXY_ADMIN_CONTRACT_PATH="../../solidity/contracts/@openzeppelin/contracts/ProxyAdmin.sol" +PROXY_CONTRACT_PATH="../../solidity/contracts/@openzeppelin/contracts/TransparentUpgradeableProxy.sol" +COSMOS_TOKEN_CONTRACT_PATH="../../solidity/contracts/CosmosToken.sol" +COSMOS_TOKEN_DEPLOY_ARGS="Injective INJ 18" +COSMOS_TOKEN_MAX_AMOUNT=100000000000000000000000000 # 100 million tokens that will be minted straight to Peggy proxy + +# Ethereum opts +DEPLOYER_PK=$(cat ../ethereum/geth/clique_signer.key) +ETH_ENDPOINT="http://localhost:8545" +TX_OPTS="-P $DEPLOYER_PK --endpoint $ETH_ENDPOINT" +COSMOS_TOKEN_OPTS="$TX_OPTS --name CosmosERC20 --source $COSMOS_TOKEN_CONTRACT_PATH" +PEGGY_OPTS="$TX_OPTS --name Peggy --source $PEGGY_CONTRACT_PATH" +PROXY_ADMIN_OPTS="$TX_OPTS --name ProxyAdmin --source $PROXY_ADMIN_CONTRACT_PATH" +PEGGY_PROXY_OPTS="$TX_OPTS --name TransparentUpgradeableProxy --source $PROXY_CONTRACT_PATH" + + +echo "Deploying Peggy.sol ..." +peggy_impl_address=$(etherman $PEGGY_OPTS deploy) + +sleep 1 + +echo "Initializing Peggy.sol ..." +peggy_init_data=$(etherman $PEGGY_OPTS tx --bytecode "$peggy_impl_address" initialize $PEGGY_INIT_ARGS) + +sleep 1 + +echo "Deploying ProxyAdmin.sol ..." +proxy_admin_address=$(etherman $PROXY_ADMIN_OPTS deploy) + +sleep 1 + +echo "Deploying TransparentUpgradeableProxy.sol ..." +peggy_proxy_address=$(etherman $PEGGY_PROXY_OPTS deploy "$peggy_impl_address" "$proxy_admin_address" "$peggy_init_data") + +sleep 1 + +echo "Deploying Injective (CosmosERC20.sol) token ..." +coin_contract_address=$(etherman $COSMOS_TOKEN_OPTS deploy $COSMOS_TOKEN_DEPLOY_ARGS) + +sleep 1 + +echo "Minting 100_000_000 Injective tokens to Peggy.sol proxy ..." +etherman $COSMOS_TOKEN_OPTS tx "$coin_contract_address" mint "$peggy_proxy_address" $COSMOS_TOKEN_MAX_AMOUNT + +sleep 1 + +echo "Contract addresses:" +echo " $peggy_impl_address Peggy.sol" +echo " $proxy_admin_address ProxyAdmin.sol:" +echo " $peggy_proxy_address TransparentUpgradeableProxy.sol" +echo " $coin_contract_address Injective token" +echo + +# Update peggy_params.json +peggy_params_json="./peggy_params.json" +jq --arg cosmos_coin_erc20 "$coin_contract_address" \ + --arg bridge_contract_height "$peggy_block_number" \ + --arg bridge_ethereum "$peggy_proxy_address" \ + '.messages[0].params.cosmos_coin_erc20_contract = $cosmos_coin_erc20 | + .messages[0].params.bridge_contract_start_height = $bridge_contract_height | + .messages[0].params.bridge_ethereum_address = $bridge_ethereum' \ + $peggy_params_json > tmpfile && mv tmpfile $peggy_params_json + +echo "Peggy contracts deployed!" +echo diff --git a/test/peggo/example.env b/test/peggo/example.env new file mode 100644 index 00000000..f7beae17 --- /dev/null +++ b/test/peggo/example.env @@ -0,0 +1,47 @@ +PEGGO_ENV="local" +PEGGO_LOG_LEVEL="debug" +PEGGO_SERVICE_WAIT_TIMEOUT="1m" + +PEGGO_COSMOS_CHAIN_ID="injective-333" +PEGGO_COSMOS_GRPC="tcp://localhost:9900" +PEGGO_TENDERMINT_RPC="http://localhost:26657" + +PEGGO_COSMOS_FEE_DENOM="inj" +PEGGO_COSMOS_GAS_PRICES="500000000inj" + +PEGGO_COSMOS_KEYRING="test" +PEGGO_COSMOS_KEYRING_DIR=/Users/dbrajovic/Desktop/dev/Injective/peggo/test/cosmos/data/injective-333/n0 +PEGGO_COSMOS_KEYRING_APP="injectived" +PEGGO_COSMOS_FROM=val +PEGGO_COSMOS_FROM_PASSPHRASE=12345678 +PEGGO_COSMOS_PK= +PEGGO_COSMOS_USE_LEDGER=false + +PEGGO_ETH_CHAIN_ID=50 +PEGGO_ETH_RPC="http://localhost:8545" +PEGGO_ETH_ALCHEMY_WS="" +PEGGO_ETH_CONTRACT_ADDRESS= + +PEGGO_COINGECKO_API="https://api.coingecko.com/api/v3" + +PEGGO_ETH_KEYSTORE_DIR="/Users/dbrajovic/Desktop/dev/Injective/peggo/test/ethereum/data/50/keystore" +PEGGO_ETH_FROM=0x4e9feE2BCdf6F21b17b77BD0ac9faDD6fF16B4d4 +PEGGO_ETH_PASSPHRASE=12345678 +PEGGO_ETH_PK=e85344fa1e00f06bd286b716e410ee0ad73541956c4cf59520f6db13599eb3f3 +PEGGO_ETH_USE_LEDGER=false +PEGGO_ETH_GAS_PRICE_ADJUSTMENT=1.3 +PEGGO_ETH_MAX_GAS_PRICE="500gwei" + +PEGGO_RELAY_VALSETS=true +PEGGO_RELAY_VALSET_OFFSET_DUR="3m" +PEGGO_RELAY_BATCHES=true +PEGGO_RELAY_BATCH_OFFSET_DUR="3m" +PEGGO_RELAY_PENDING_TX_WAIT_DURATION="20m" + +PEGGO_MIN_BATCH_FEE_USD=23.2 + +PEGGO_STATSD_PREFIX="peggo." +PEGGO_STATSD_ADDR="localhost:8125" +PEGGO_STATSD_STUCK_DUR="5m" +PEGGO_STATSD_MOCKING=false +PEGGO_STATSD_DISABLED=true \ No newline at end of file diff --git a/test/peggo/peggy_params.json b/test/peggo/peggy_params.json new file mode 100644 index 00000000..6438cdcc --- /dev/null +++ b/test/peggo/peggy_params.json @@ -0,0 +1,42 @@ +{ + "messages": [ + { + "@type": "/injective.peggy.v1.MsgUpdateParams", + "authority": "inj10d07y265gmmuvt4z0w9aw880jnsr700jstypyt", + "params": { + "peggy_id": "injective-peggyid", + "contract_source_hash": "", + "bridge_ethereum_address": "0x5048019d259217e6b7BC8e1E6aEfa9976B1ADFfe", + "bridge_chain_id": "50", + "signed_valsets_window": "25000", + "signed_batches_window": "25000", + "signed_claims_window": "25000", + "target_batch_timeout": "43200000", + "average_block_time": "1000", + "average_ethereum_block_time": "15000", + "slash_fraction_valset": "0.001000000000000000", + "slash_fraction_batch": "0.001000000000000000", + "slash_fraction_claim": "0.001000000000000000", + "slash_fraction_conflicting_claim": "0.001000000000000000", + "unbond_slashing_valsets_window": "25000", + "slash_fraction_bad_eth_signature": "0.001000000000000000", + "cosmos_coin_denom": "inj", + "cosmos_coin_erc20_contract": "0x7E5C521F8515017487750c13C3bF3B15f3f5f654", + "claim_slashing_enabled": false, + "bridge_contract_start_height": "13", + "valset_reward": { + "denom": "inj", + "amount": "0" + }, + "admins": [ + "inj1wfawuv6fslzjlfa4v7exv27mk6rpfeyvhvxchc" + ], + "segregated_wallet_address": "inj1dqryh824u0w7p6ajk2gsr29tgj6d0nkfwsgs46" + } + } + ], + "metadata": "ipfs://CID", + "deposit": "100000001inj", + "title": "Peggo local testing env", + "summary": "The time I needed a working environment to test the bridge" +} diff --git a/test/peggo/start_orchestrators.sh b/test/peggo/start_orchestrators.sh new file mode 100755 index 00000000..359c8056 --- /dev/null +++ b/test/peggo/start_orchestrators.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +set -e + +cd "${0%/*}" # cd in the script dir + +# Start peggo service +echo "Starting 3x Peggo orchestrators..." + +cwd=$(pwd) +example_env=$cwd/example.env +localhost_tcp="tcp://localhost" +localhost_http="http://localhost" + +n0_peggo_dir=$cwd/data/n0 +n1_peggo_dir=$cwd/data/n1 +n2_peggo_dir=$cwd/data/n2 + +n0_peggo_env=$n0_peggo_dir/.env +n1_peggo_env=$n1_peggo_dir/.env +n2_peggo_env=$n2_peggo_dir/.env + +mkdir -p "$n0_peggo_dir" && touch "$n0_peggo_env" +mkdir -p "$n1_peggo_dir" && touch "$n1_peggo_env" +mkdir -p "$n2_peggo_dir" && touch "$n2_peggo_env" + +n0_cosmos_grpc="$localhost_tcp:9090" +n1_cosmos_grpc="$localhost_tcp:9091" +n2_cosmos_grpc="$localhost_tcp:9092" + +n0_tendermint_rpc="$localhost_http:26657" +n1_tendermint_rpc="$localhost_http:26667" +n2_tendermint_rpc="$localhost_http:26677" + +chain_dir=$(realpath "../cosmos/data/injective-333") +n0_home_dir=$chain_dir/n0 +n1_home_dir=$chain_dir/n1 +n2_home_dir=$chain_dir/n2 + +n0_eth_pk="e85344fa1e00f06bd286b716e410ee0ad73541956c4cf59520f6db13599eb3f3" +n1_eth_pk="60f6ee19454b8ff45693cd54c55860785e4af9eeb06d6c5617568458e4ca5c54" +n2_eth_pk="21eeff959d9752704e3f1ad6562fd0458c003bce0947e5aecf07b602f4e457aa" + +n0_eth_addr="0x4e9feE2BCdf6F21b17b77BD0ac9faDD6fF16B4d4" +n1_eth_addr="0xec43B0eA83844Cbe5A20F5371604BD452Cb1012c" +n2_eth_addr="0x8B094eD440900CEB75B83A22eD8A2C7582B442C2" + +sed -e "s|^PEGGO_ETH_FROM=.*|PEGGO_ETH_FROM=\"$n0_eth_addr\"|" \ + -e "s|^PEGGO_ETH_PK=.*|PEGGO_ETH_PK=\"$n0_eth_pk\"|" \ + -e "s|^PEGGO_COSMOS_KEYRING_DIR=.*|PEGGO_COSMOS_KEYRING_DIR=\"$n0_home_dir\"|" \ + -e "s|^PEGGO_COSMOS_GRPC=.*|PEGGO_COSMOS_GRPC=\"$n0_cosmos_grpc\"|" \ + -e "s|^PEGGO_TENDERMINT_RPC=.*|PEGGO_TENDERMINT_RPC=\"$n0_tendermint_rpc\"|" \ + "$example_env" > "$n0_peggo_env" + +sed -e "s|^PEGGO_ETH_FROM=.*|PEGGO_ETH_FROM=\"$n1_eth_addr\"|" \ + -e "s|^PEGGO_ETH_PK=.*|PEGGO_ETH_PK=\"$n1_eth_pk\"|" \ + -e "s|^PEGGO_COSMOS_KEYRING_DIR=.*|PEGGO_COSMOS_KEYRING_DIR=\"$n1_home_dir\"|" \ + -e "s|^PEGGO_COSMOS_GRPC=.*|PEGGO_COSMOS_GRPC=\"$n1_cosmos_grpc\"|" \ + -e "s|^PEGGO_TENDERMINT_RPC=.*|PEGGO_TENDERMINT_RPC=\"$n1_tendermint_rpc\"|" \ + "$example_env" > "$n1_peggo_env" + +sed -e "s|^PEGGO_ETH_FROM=.*|PEGGO_ETH_FROM=\"$n2_eth_addr\"|" \ + -e "s|^PEGGO_ETH_PK=.*|PEGGO_ETH_PK=\"$n2_eth_pk\"|" \ + -e "s|^PEGGO_COSMOS_KEYRING_DIR=.*|PEGGO_COSMOS_KEYRING_DIR=\"$n2_home_dir\"|" \ + -e "s|^PEGGO_COSMOS_GRPC=.*|PEGGO_COSMOS_GRPC=\"$n2_cosmos_grpc\"|" \ + -e "s|^PEGGO_TENDERMINT_RPC=.*|PEGGO_TENDERMINT_RPC=\"$n2_tendermint_rpc\"|" \ + "$example_env" > "$n2_peggo_env" + +# One relayer has lower min batch fee +CHEAP_RELAYER="${CHEAP_RELAYER:-false}" +if [[ "$CHEAP_RELAYER" == true ]]; then + echo "Setting n2 orchestrator with PEGGO_MIN_BATCH_FEE_USD to 10" + echo "$n2_peggo_env" + sed -i '' 's/^PEGGO_MIN_BATCH_FEE_USD=.*/PEGGO_MIN_BATCH_FEE_USD=10/' "$n2_peggo_env" +fi + +# Start a new tmux session +tmux new-session -d -s mysession + +# Split the terminal vertically into three equally spaced panes +tmux split-window -v +tmux split-window -v +tmux select-layout even-vertical + +# Select each pane and run a command from a different directory +peggo_cmd="peggo orchestrator" +tmux send-keys -t 0 "cd $n0_peggo_dir" C-m "$peggo_cmd" C-m +tmux send-keys -t 1 "cd $n1_peggo_dir" C-m "$peggo_cmd" C-m +tmux send-keys -t 2 "cd $n2_peggo_dir" C-m "$peggo_cmd" C-m + +# Attach to the tmux session to view the processes +tmux attach-session -t mysession + + diff --git a/test/peggo/update_peggy_module.sh b/test/peggo/update_peggy_module.sh new file mode 100755 index 00000000..ce753a58 --- /dev/null +++ b/test/peggo/update_peggy_module.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +set -e + +cd "${0%/*}" # cd in the script dir + +PASSPHRASE="12345678" +TX_OPTS="--chain-id injective-333 --keyring-backend test --broadcast-mode sync --yes" + +peggy_params_json="./peggy_params.json" +chain_dir="../cosmos/data/injective-333" +n0_home_dir=$chain_dir/n0 +n1_home_dir=$chain_dir/n1 +n2_home_dir=$chain_dir/n2 + +# usage: resp_check [resp] [err_msg] +resp_check() { + if [ "$(echo -e "$1" | awk -F"'" '/raw_log: /{print $2}')" != "[]" ]; then + echo "$2" + exit 1 + fi +} + +echo "Peggy params update:" +cat $peggy_params_json +echo +echo "Submitting gov proposal to update Peggy module params..." + +resp="$(yes $PASSPHRASE | injectived tx gov submit-proposal $peggy_params_json --home $n0_home_dir --from user --gas 2000000 --gas-prices 500000000inj $TX_OPTS)" +echo "$resp" + +sleep 2 + +current_proposal_id=$(curl 'http://localhost:10337/cosmos/gov/v1beta1/proposals?proposal_status=0&pagination.limit=1&pagination.reverse=true' 2>/dev/null | jq -r '.proposals[].proposal_id') + +yes $PASSPHRASE | injectived tx gov vote "$current_proposal_id" yes --home $n0_home_dir --from val --gas-prices 500000000inj $TX_OPTS &>/dev/null +yes $PASSPHRASE | injectived tx gov vote "$current_proposal_id" yes --home $n1_home_dir --from val --gas-prices 500000000inj $TX_OPTS &>/dev/null +yes $PASSPHRASE | injectived tx gov vote "$current_proposal_id" yes --home $n2_home_dir --from val --gas-prices 500000000inj $TX_OPTS &>/dev/null + +sleep 8 +echo "Gov proposal passed" + +n0_inj_addr="inj1cml96vmptgw99syqrrz8az79xer2pcgp0a885r" +n1_inj_addr="inj1jcltmuhplrdcwp7stlr4hlhlhgd4htqhe4c0cs" +n2_inj_addr="inj1dzqd00lfd4y4qy2pxa0dsdwzfnmsu27hgttswz" + +n0_eth_addr="0x4e9feE2BCdf6F21b17b77BD0ac9faDD6fF16B4d4" +n1_eth_addr="0xec43B0eA83844Cbe5A20F5371604BD452Cb1012c" +n2_eth_addr="0x8B094eD440900CEB75B83A22eD8A2C7582B442C2" + +echo "Registering orchestrator ETH addresses..." +injectived tx peggy set-orchestrator-address $n0_inj_addr $n0_inj_addr $n0_eth_addr --home $n0_home_dir --from=val --gas-prices 100000000000000inj $TX_OPTS &>/dev/null +injectived tx peggy set-orchestrator-address $n1_inj_addr $n1_inj_addr $n1_eth_addr --home $n1_home_dir --from=val --gas-prices 100000000000000inj $TX_OPTS &>/dev/null +injectived tx peggy set-orchestrator-address $n2_inj_addr $n2_inj_addr $n2_eth_addr --home $n2_home_dir --from=val --gas-prices 100000000000000inj $TX_OPTS &>/dev/null + +sleep 2 +echo "Orchestrator addresses registered" +echo " * val1=$n0_inj_addr orch1=$n0_inj_addr eth1=$n0_eth_addr" +echo " * val2=$n0_inj_addr orch2=$n0_inj_addr eth2=$n0_eth_addr" +echo " * val3=$n0_inj_addr orch3=$n0_inj_addr eth3=$n0_eth_addr" diff --git a/test/run.sh b/test/run.sh new file mode 100755 index 00000000..ff452db1 --- /dev/null +++ b/test/run.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +cd "${0%/*}" # cd in the script dir + +killall injectived geth &>/dev/null || true + +cwd=$(pwd) +cosmos_dir="$cwd/cosmos" +eth_dir="$cwd/ethereum" +peggo_dir="$cwd/peggo" + +rm -rf "$cosmos_dir/data" +rm -rf "$eth_dir/data" +rm -rf "$peggo_dir/data" +rm -rf "$peggo_dir/build" + +# Start the Ethereum chain +"$eth_dir"/geth-init.sh +"$eth_dir"/geth.sh + +# Start the Cosmos chain +"$cosmos_dir"/multinode.sh injectived + +# Deploy Peggy contracts suite +"$peggo_dir"/deploy_peggy_contract_suite.sh + +# Update Peggy module and register orchestrators +"$peggo_dir"/update_peggy_module.sh + +# Start the orchestrators +"$peggo_dir"/start_orchestrators.sh diff --git a/test/send_to_eth.sh b/test/send_to_eth.sh new file mode 100755 index 00000000..8424d3e7 --- /dev/null +++ b/test/send_to_eth.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +cd "${0%/*}" # cd in the script dir + +passphrase=12345678 + +# Send INJ tokens +yes $passphrase | injectived tx peggy send-to-eth "0xBbDf3283d1Cf510c17B4FfA1b900F444bE4A4A4e" 30inj 3000000000000000000inj --chain-id=injective-333 --gas-prices 500000000inj --keyring-backend test --broadcast-mode=sync --yes --home /Users/dbrajovic/Desktop/dev/Injective/peggo/test/cosmos/data/injective-333/n0 --from user + +# Send WAT tokens (premined) +#yes $passphrase | injectived tx peggy send-to-eth "0xBbDf3283d1Cf510c17B4FfA1b900F444bE4A4A4e" 10wut 1500000000000000000wut --chain-id=injective-333 --gas-prices 500000000inj --keyring-backend test --broadcast-mode=sync --yes --home /Users/dbrajovic/Desktop/dev/Injective/peggo/test/cosmos/data/injective-333/n0 --from user diff --git a/test/send_to_inj.sh b/test/send_to_inj.sh new file mode 100755 index 00000000..db67b85a --- /dev/null +++ b/test/send_to_inj.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +cd "${0%/*}" # cd in the script dir + +deployer_pk=$(cat ./ethereum/geth/clique_signer.key) +peggy_contract="../solidity/contracts/Peggy.sol" +cosmos_token_contract="../solidity/contracts/CosmosToken.sol" + +peggy_contract_address=0x5048019d259217e6b7BC8e1E6aEfa9976B1ADFfe +inj_coin_contract_address=0x7E5C521F8515017487750c13C3bF3B15f3f5f654 + +#etherman --name CosmosERC20 --source "$cosmos_token_contract" -P "$deployer_pk" tx "$inj_coin_contract_address" approve "$peggy_contract_address" 100 +etherman --name Peggy --source "$peggy_contract" -P "$deployer_pk" tx "$peggy_contract_address" sendToInjective "$inj_coin_contract_address" 000000000000000000000000727aee334987c52fa7b567b2662bdbb68614e48c 10 "" +