-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathblockchain.go
More file actions
118 lines (106 loc) · 3.62 KB
/
blockchain.go
File metadata and controls
118 lines (106 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package blockchain
import (
"fmt"
"github.com/testcontainers/testcontainers-go"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
)
// Blockchain node type
const (
TypeAnvil = "anvil"
TypeAnvilZKSync = "anvil-zksync"
TypeGeth = "geth"
TypeBesu = "besu"
TypeSolana = "solana"
TypeAptos = "aptos"
TypeSui = "sui"
TypeTron = "tron"
TypeTon = "ton"
)
// Blockchain node family
const (
FamilyEVM = "evm"
FamilySolana = "solana"
FamilyAptos = "aptos"
FamilySui = "sui"
FamilyTron = "tron"
FamilyTon = "ton"
)
// Input is a blockchain network configuration params
type Input struct {
// Common EVM fields
Type string `toml:"type" validate:"required,oneof=anvil geth besu solana aptos tron sui ton" envconfig:"net_type"`
Image string `toml:"image"`
PullImage bool `toml:"pull_image"`
Port string `toml:"port"`
// Not applicable to Solana, ws port for Solana is +1 of port
WSPort string `toml:"port_ws"`
ChainID string `toml:"chain_id"`
DockerCmdParamsOverrides []string `toml:"docker_cmd_params"`
Out *Output `toml:"out"`
// Solana fields
// publickey to mint when solana-test-validator starts
PublicKey string `toml:"public_key"`
ContractsDir string `toml:"contracts_dir"`
// programs to deploy on solana-test-validator start
// a map of program name to program id
// there needs to be a matching .so file in contracts_dir
SolanaPrograms map[string]string `toml:"solana_programs"`
ContainerResources *framework.ContainerResources `toml:"resources"`
CustomPorts []string `toml:"custom_ports"`
// Ton - MyLocalTon essesntial services to run tests
DockerComposeFileURL string `toml:"docker_compose_file_url"`
TonCoreServices []string `toml:"ton_core_services"`
}
// Output is a blockchain network output, ChainID and one or more nodes that forms the network
type Output struct {
UseCache bool `toml:"use_cache"`
Type string `toml:"type"`
Family string `toml:"family"`
ContainerName string `toml:"container_name"`
NetworkSpecificData *NetworkSpecificData `toml:"network_specific_data"`
Container testcontainers.Container `toml:"-"`
ChainID string `toml:"chain_id"`
Nodes []*Node `toml:"nodes"`
}
type NetworkSpecificData struct {
SuiAccount *SuiWalletInfo
}
// Node represents blockchain node output, URLs required for connection locally and inside docker network
type Node struct {
ExternalWSUrl string `toml:"ws_url"`
ExternalHTTPUrl string `toml:"http_url"`
InternalWSUrl string `toml:"internal_ws_url"`
InternalHTTPUrl string `toml:"internal_http_url"`
}
// NewBlockchainNetwork this is an abstraction that can spin up various blockchain network simulators
func NewBlockchainNetwork(in *Input) (*Output, error) {
var out *Output
var err error
switch in.Type {
case TypeAnvil:
out, err = newAnvil(in)
case TypeGeth:
out, err = newGeth(in)
case TypeBesu:
out, err = newBesu(in)
case TypeSolana:
out, err = newSolana(in)
case TypeAptos:
out, err = newAptos(in)
case TypeSui:
out, err = newSui(in)
case TypeTron:
out, err = newTron(in)
case TypeAnvilZKSync:
out, err = newAnvilZksync(in)
case TypeTon:
out, err = newTon(in)
default:
return nil, fmt.Errorf("blockchain type is not supported or empty, must be 'anvil' or 'geth'")
}
if err != nil {
return nil, err
}
in.Out = out
return out, nil
}