Skip to content

Commit

Permalink
chore: revert property name from chain to network
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Jun 3, 2024
1 parent a5712a4 commit 0c0df8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ BitcoindContainer<?> bitcoindContainer() {

private List<String> buildCommandList() {
ImmutableList.Builder<String> requiredCommandsBuilder = ImmutableList.<String>builder()
.add("-chain=" + this.properties.getChain().getChain())
.add("-chain=" + this.properties.getNetwork().getChain())
.add("-rpcport=" + this.properties.getRpcport())
.add("-port=" + this.properties.getPort());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class BitcoindContainerProperties extends AbstractContainerProperties imp
private static final int REGTEST_DEFAULT_RPC_PORT = 18443;
private static final int REGTEST_DEFAULT_P2P_PORT = 18444;

private static final Chain DEFAULT_CHAIN = Chain.regtest;
private static final Network DEFAULT_NETWORK = Network.regtest;

@Beta
private static final List<String> reservedCommands = ImmutableList.<String>builder()
Expand All @@ -69,7 +69,7 @@ public class BitcoindContainerProperties extends AbstractContainerProperties imp
*/
@Getter
@RequiredArgsConstructor
public enum Chain {
public enum Network {
mainnet("main"),
testnet("test"),
regtest("regtest");
Expand All @@ -82,7 +82,7 @@ public BitcoindContainerProperties() {
super(defaultDockerImageName, reservedCommands);
}

private Chain chain;
private Network network;

/**
* RPC port
Expand All @@ -104,8 +104,8 @@ public BitcoindContainerProperties() {
*/
private String rpcpassword;

public Chain getChain() {
return this.chain != null ? this.chain : DEFAULT_CHAIN;
public Network getNetwork() {
return this.network != null ? this.network : DEFAULT_NETWORK;
}

public Optional<String> getRpcuser() {
Expand All @@ -117,15 +117,15 @@ public Optional<String> getRpcpassword() {
}

public int getRpcport() {
return rpcport != null ? rpcport : switch (getChain()) {
return rpcport != null ? rpcport : switch (getNetwork()) {
case mainnet -> MAINNET_DEFAULT_RPC_PORT;
case testnet -> TESTNET_DEFAULT_RPC_PORT;
case regtest -> REGTEST_DEFAULT_RPC_PORT;
};
}

public int getPort() {
return port != null ? port : switch (getChain()) {
return port != null ? port : switch (getNetwork()) {
case mainnet -> MAINNET_DEFAULT_P2P_PORT;
case testnet -> TESTNET_DEFAULT_P2P_PORT;
case regtest -> REGTEST_DEFAULT_P2P_PORT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void beansWithCustomConfigAreCreated() {
assertThat(properties, is(notNullValue()));
assertThat(properties.getRpcuser().orElseThrow(), is("myrpcuser"));
assertThat(properties.getRpcpassword().orElseThrow(), is("correcthorsebatterystaple"));
assertThat(properties.getChain(), is(BitcoindContainerProperties.Chain.regtest));
assertThat(properties.getNetwork(), is(BitcoindContainerProperties.Network.regtest));

assertThat(properties.getCommands(), hasSize(3));
assertThat(properties.getCommands(), hasItem("-printtoconsole"));
Expand Down Expand Up @@ -156,7 +156,7 @@ void throwOnWrongNetworkPropertiesValues() {
"org.tbk.spring.testcontainer.bitcoind.rpcuser=myrpcuser",
"org.tbk.spring.testcontainer.bitcoind.rpcpassword=password",
"org.tbk.spring.testcontainer.bitcoind.rpcport=7777",
"org.tbk.spring.testcontainer.bitcoind.chain=nakamoto",
"org.tbk.spring.testcontainer.bitcoind.network=nakamoto",
"org.tbk.spring.testcontainer.bitcoind.commands=-printtoconsole, -debug=1, -logips=1"
)
.run(context -> {
Expand All @@ -168,7 +168,7 @@ void throwOnWrongNetworkPropertiesValues() {
Throwable rootCause = Throwables.getRootCause(e);

assertThat(rootCause, is(instanceOf(IllegalArgumentException.class)));
assertThat(rootCause.getMessage(), is("No enum constant %s.%s".formatted(BitcoindContainerProperties.Chain.class.getCanonicalName(), "nakamoto")));
assertThat(rootCause.getMessage(), is("No enum constant %s.%s".formatted(BitcoindContainerProperties.Network.class.getCanonicalName(), "nakamoto")));
}
});
}
Expand Down Expand Up @@ -245,7 +245,7 @@ void defaultRegtestValuesTest() {
BitcoindContainerProperties properties = context.getBean(BitcoindContainerProperties.class);
assertThat(properties, is(notNullValue()));

assertThat(properties.getChain(), is(BitcoindContainerProperties.Chain.regtest));
assertThat(properties.getNetwork(), is(BitcoindContainerProperties.Network.regtest));
assertThat(properties.getRpcport(), is(18443));
assertThat(properties.getPort(), is(18444));

Expand All @@ -259,14 +259,14 @@ void defaultMainnetValuesTest() {
"org.tbk.spring.testcontainer.bitcoind.enabled=true",
"org.tbk.spring.testcontainer.bitcoind.rpcuser=myrpcuser",
"org.tbk.spring.testcontainer.bitcoind.rpcpassword=correcthorsebatterystaple",
"org.tbk.spring.testcontainer.bitcoind.chain=mainnet",
"org.tbk.spring.testcontainer.bitcoind.network=mainnet",
"org.tbk.spring.testcontainer.bitcoind.commands=-printtoconsole, -debug=1, -logips=1"
)
.run(context -> {
BitcoindContainerProperties properties = context.getBean(BitcoindContainerProperties.class);
assertThat(properties, is(notNullValue()));

assertThat(properties.getChain(), is(BitcoindContainerProperties.Chain.mainnet));
assertThat(properties.getNetwork(), is(BitcoindContainerProperties.Network.mainnet));
assertThat(properties.getRpcport(), is(8332));
assertThat(properties.getPort(), is(8333));
});
Expand All @@ -279,14 +279,14 @@ void defaultTestnetValuesTest() {
"org.tbk.spring.testcontainer.bitcoind.enabled=true",
"org.tbk.spring.testcontainer.bitcoind.rpcuser=myrpcuser",
"org.tbk.spring.testcontainer.bitcoind.rpcpassword=correcthorsebatterystaple",
"org.tbk.spring.testcontainer.bitcoind.chain=testnet",
"org.tbk.spring.testcontainer.bitcoind.network=testnet",
"org.tbk.spring.testcontainer.bitcoind.commands=-printtoconsole, -debug=1, -logips=1"
)
.run(context -> {
BitcoindContainerProperties properties = context.getBean(BitcoindContainerProperties.class);
assertThat(properties, is(notNullValue()));

assertThat(properties.getChain(), is(BitcoindContainerProperties.Chain.testnet));
assertThat(properties.getNetwork(), is(BitcoindContainerProperties.Network.testnet));
assertThat(properties.getRpcport(), is(18332));
assertThat(properties.getPort(), is(18333));
});
Expand Down

0 comments on commit 0c0df8e

Please sign in to comment.