-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1659753
commit faf9030
Showing
8 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
"github.com/skip-mev/petri/provider" | ||
) | ||
|
||
type ChainI interface { | ||
GetConfig() ChainConfig | ||
} | ||
|
||
type ChainConfig struct { | ||
Denom string | ||
Decimals uint64 | ||
NumValidators int | ||
NumNodes int | ||
|
||
BinaryName string | ||
|
||
Image provider.ImageDefinition | ||
SidecarImage provider.ImageDefinition | ||
|
||
GasPrices string | ||
GasAdjustment float64 | ||
|
||
Bech32Prefix string | ||
|
||
EncodingConfig testutil.TestEncodingConfig | ||
|
||
HomeDir string | ||
SidecarHomeDir string | ||
SidecarPorts []string | ||
SidecarArgs []string | ||
|
||
CoinType string | ||
ChainId string | ||
|
||
ModifyGenesis GenesisModifier | ||
|
||
NodeCreator NodeCreator | ||
} | ||
|
||
type GenesisModifier func([]byte) ([]byte, error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package types | ||
|
||
const ( | ||
ValidatorKeyName = "validator" | ||
FaucetAccountKeyName = "faucet" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module github.com/skip-mev/petri/types | ||
|
||
go 1.21.3 | ||
|
||
replace ( | ||
github.com/skip-mev/petri/provider => ../provider | ||
github.com/skip-mev/petri/util => ../util | ||
) | ||
|
||
require github.com/skip-mev/petri/provider v0.0.0-00010101000000-000000000000 | ||
|
||
require github.com/skip-mev/petri/util v0.0.0-00010101000000-000000000000 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package types | ||
|
||
import ( | ||
"context" | ||
rpcclient "github.com/cometbft/cometbft/rpc/client" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/skip-mev/petri/provider" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type NodeConfig struct { | ||
Name string | ||
|
||
IsValidator bool | ||
|
||
Chain ChainI | ||
Provider provider.Provider | ||
} | ||
|
||
type NodeCreator func(context.Context, NodeConfig) (NodeI, error) | ||
|
||
type NodeI interface { | ||
GetTMClient(context.Context) (rpcclient.Client, error) | ||
GetGRPCClient(context.Context) (*grpc.ClientConn, error) | ||
Height(context.Context) (uint64, error) | ||
|
||
InitHome(context.Context) error | ||
|
||
AddGenesisAccount(context.Context, string, []sdk.Coin) error | ||
GenerateGenTx(context.Context, sdk.Coin) error | ||
CopyGenTx(context.Context, NodeI) error | ||
CollectGenTxs(context.Context) error | ||
|
||
GenesisFileContent(context.Context) ([]byte, error) | ||
OverwriteGenesisFile(context.Context, []byte) error | ||
|
||
CreateWallet(context.Context, string) (WalletI, error) | ||
RecoverKey(context.Context, string, string) error | ||
KeyBech32(context.Context, string, string) (string, error) | ||
|
||
SetDefaultConfigs(context.Context) error | ||
SetPersistentPeers(context.Context, string) error | ||
|
||
NodeId(context.Context) (string, error) | ||
|
||
GetTask() *provider.Task | ||
GetIP(context.Context) (string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package types | ||
|
||
import cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
|
||
type WalletI interface { | ||
FormattedAddress() string | ||
KeyName() string | ||
Mnemonic() string | ||
Address() []byte | ||
FormattedAddressWithPrefix(prefix string) string | ||
PublicKey() (cryptotypes.PubKey, error) | ||
PrivateKey() (cryptotypes.PrivKey, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package util | ||
|
||
import "bytes" | ||
|
||
// CleanDockerOutput removes trailing bytes from Docker's stdout pipe | ||
func CleanDockerOutput(stdout string) string { | ||
cleanedLine := bytes.TrimFunc([]byte(stdout), func(r rune) bool { | ||
return !(r >= 0x20 && r <= 0x7E) | ||
}) | ||
|
||
cleanedLine = bytes.TrimSpace(cleanedLine) | ||
cleanedLine = bytes.Trim(cleanedLine, "\n.") | ||
|
||
return string(cleanedLine) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/skip-mev/petri/util | ||
|
||
go 1.21.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package util | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func WaitForCondition(timeoutAfter, pollingInterval time.Duration, fn func() (bool, error)) error { | ||
ctx, cancel := context.WithTimeout(context.Background(), timeoutAfter) | ||
defer cancel() | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return fmt.Errorf("failed waiting for condition after %f seconds", timeoutAfter.Seconds()) | ||
case <-time.After(pollingInterval): | ||
reachedCondition, err := fn() | ||
if err != nil { | ||
return fmt.Errorf("error occurred while waiting for condition: %s", err) | ||
} | ||
|
||
if reachedCondition { | ||
return nil | ||
} | ||
} | ||
} | ||
} |