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

fix: geth infura mode #363

Merged
merged 6 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
language: generic
language: python
python:
- "3.8"
arch:
- amd64
- arm64
Expand All @@ -8,8 +10,11 @@ services:
- docker
before_script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- pip install pexpect
script: tools/push --no-manifest-list
jobs:
include:
- stage: Create and push manifest lists
script: tools/push --manifest-list
script: tools/push --manifest-list
- stage: Test common cases
script: tools/test
6 changes: 6 additions & 0 deletions images/utils/launcher/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,12 @@ def update_geth(self, parsed):
print("Warning: Please use field \"mode\" to specify Infura usage.")
node["mode"] = "infura"

if "mode" in parsed:
value = parsed["mode"]
if value not in ["native", "external", "infura"]:
raise NetworkConfigFileValueError("Invalid value of field \"mode\": " + value)
node["mode"] = parsed["mode"]

if node["mode"] == "external":
if "rpc-host" in parsed:
value = parsed["rpc-host"]
Expand Down
11 changes: 11 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .test_custom_network_dir import test, cleanup

exit_code = 0
try:
test()
except:
exit_code = 1
finally:
cleanup()

exit(exit_code)
Empty file added tests/__main__.py
Empty file.
229 changes: 229 additions & 0 deletions tests/test_custom_network_dir/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import os
from shutil import copyfile
import pexpect
import time
from subprocess import check_output, CalledProcessError, PIPE


def cleanup_images(network):
print("[CLEANUP] {} images".format(network))


def cleanup_containers(network):
print("[CLEANUP] {} containers".format(network))
containers = []
try:
containers = check_output("docker ps --filter name={} -q -a".format(network), shell=True, stderr=PIPE).decode().splitlines()
except CalledProcessError:
pass

if len(containers) > 0:
try:
cmd = "docker stop {}".format(" ".join(containers))
print(cmd)
check_output(cmd, shell=True, stderr=PIPE).decode().splitlines()
except CalledProcessError:
pass

try:
cmd = "docker rm {}".format(" ".join(containers))
print(cmd)
check_output(cmd, shell=True, stderr=PIPE).decode().splitlines()
except CalledProcessError:
pass

cleanup_images(network)


def cleanup():
cleanup_containers("simnet")
cleanup_containers("testnet")
cleanup_containers("mainnet")
print("[CLEANUP] Removing ~/.xud-docker")
os.system("sudo rm -rf ~/.xud-docker")
print("[CLEANUP] Removing /tmp/xud-testnet")
os.system("sudo rm -rf /tmp/xud-testnet")
print("[CLEANUP] Removing /tmp/xud-testnet-backup")
os.system("sudo rm -rf /tmp/xud-testnet-backup")


def expect_multilines(child, content):
pass


def create_wallet(child, retry=0):
if retry == 0:
print("[EXPECT] Create/Restore choice")
try:
child.expect("Do you want to create a new xud environment or restore an existing one?", timeout=60)
print(child.before, end="")
print(child.match.group(0))

child.expect("Please choose: ")
print(child.before, end="")
print(child.match.group(0))

child.sendline("1\r")
except pexpect.exceptions.EOF:
print("Error: Exits unexpectedly")
print(child.before)
exit(1)
except pexpect.exceptions.TIMEOUT:
print("Error: Timeout")
print(child.before)
exit(1)

print("[EXPECT] Xud master password")
try:
child.expect("You are creating an xud node key and underlying wallets.", timeout=180)
print(child.before, end="")
print(child.match.group(0))

child.expect("Enter a password: ")
print(child.before, end="")
print(child.match.group(0))
child.sendline("12345678\r")

child.expect("Re-enter password: ")
print(child.before, end="")
print(child.match.group(0))
child.sendline("12345678\r")

i = child.expect([
"----------------------BEGIN XUD SEED---------------------",
"Please choose: "
])
print(child.before, end="")
print(child.match.group(0))

if i == 0:
child.expect("-----------------------END XUD SEED----------------------")
seed = child.before
print(seed)
elif i == 1:
child.sendline("1\r")
print("Wait 5 seconds")
time.sleep(5)
create_wallet(child, retry=retry + 1)
return

child.expect("YOU WILL NOT BE ABLE TO DISPLAY YOUR XUD SEED AGAIN. Press ENTER to continue...")
print(child.before, end="")
print(child.match.group(0))
child.sendline("\r")
except pexpect.exceptions.EOF:
print("Error: Exits unexpectedly")
print(child.before)
exit(1)
except pexpect.exceptions.TIMEOUT:
print("Error: Timeout")
print(child.before)
exit(1)


def test():
cleanup()

backup_dir = "/tmp/xud-testnet-backup"
os.mkdir(backup_dir)

home_dir = os.path.expanduser("~/.xud-docker/")
os.mkdir(home_dir)
copyfile(os.path.dirname(__file__) + "/xud-docker.conf", home_dir + "/xud-docker.conf")

network_dir = "/tmp/xud-testnet"
os.mkdir(network_dir)
copyfile(os.path.dirname(__file__) + "/testnet.conf", network_dir + "/testnet.conf")

os.system("sed -i.bak 's/<id>/{}/' {}".format(os.environ["INFURA_PROJECT_ID"], network_dir + "/testnet.conf"))
os.system("sed -i.bak 's/<secret>/{}/' {}".format(os.environ["INFURA_PROJECT_SECRET"], network_dir + "/testnet.conf"))

child = pexpect.spawnu("bash setup.sh -b fix/geth-mode --nodes-json ./nodes.json")

print("[EXPECT] Network choosing (testnet)")
try:
child.expect("Please choose the network: ")
print(child.before, end="")
print(child.match.group(0))
child.sendline("2")
except pexpect.exceptions.EOF:
print("Error: Exits unexpectedly")
print(child.before)
exit(1)
except pexpect.exceptions.TIMEOUT:
print("Error: Timeout")
print(child.before)
exit(1)

print("[EXPECT] Launching testnet environment")
try:
child.expect("🚀 Launching testnet environment", timeout=90)
print(child.before, end="")
print(child.match.group(0))
except pexpect.exceptions.EOF:
print("Error: Exits unexpectedly")
print(child.before)
exit(1)
except pexpect.exceptions.TIMEOUT:
print("Error: Timeout")
print(child.before)
exit(1)

print("[EXPECT] Checking for updates")
try:
child.expect("🌍 Checking for updates...")
print(child.before, end="")
print(child.match.group(0))
except pexpect.exceptions.EOF:
print("Error: Exits unexpectedly")
print(child.before)
exit(1)
except pexpect.exceptions.TIMEOUT:
print("Error: Timeout")
print(child.before)
exit(1)

create_wallet(child)

print("[EXPECT] Backup location setup")
try:
child.expect("Enter path to backup location: ")
print(child.before, end="")
print(child.match.group(0))
child.sendline("/tmp/xud-testnet-backup\r")

child.expect("Checking backup location...")
print(child.before, end="")
print(child.match.group(0))

except pexpect.exceptions.EOF:
print("Error: Exits unexpectedly")
print(child.before)
exit(1)
except pexpect.exceptions.TIMEOUT:
print("Error: Timeout")
print(child.before)
exit(1)

print("[Expect] Xudctl shell")
try:
child.expect("testnet > ")
print(child.before, end="")
print(child.match.group(0))
child.sendline("status\r")

child.expect("testnet > ")
print(child.before, end="")
print(child.match.group(0))
child.sendline("exit\r")

child.eof()

except pexpect.exceptions.EOF:
print("Error: Exits unexpectedly")
print(child.before)
exit(1)
except pexpect.exceptions.TIMEOUT:
print("Error: Timeout")
print(child.before)
exit(1)
103 changes: 103 additions & 0 deletions tests/test_custom_network_dir/cli.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
1) Simnet
2) Testnet
3) Mainnet
Please choose the network: 2
🚀 Launching testnet environment
Warning: Using deprecated field "neutrino". Please use "mode" instead.
Warning: Using deprecated field "neutrino". Please use "mode" instead.
Warning: Please use field "mode" to specify Infura usage.
🌍 Checking for updates...
- Container testnet_lndbtc_1: missing
- Container testnet_lndltc_1: missing
- Container testnet_raiden_1: missing
- Container testnet_xud_1: missing
Creating testnet_lndbtc_1...
Creating testnet_lndltc_1...
Creating testnet_raiden_1...
Creating testnet_xud_1...
Do you want to create a new xud environment or restore an existing one?
1) Create New
2) Restore Existing
Please choose: 1

You are creating an xud node key and underlying wallets. All will be secured by
a single password provided below.

Enter a password:
Re-enter password:

xud is starting... try again in a few seconds
Do you want to create a new xud environment or restore an existing one?
1) Create New
2) Restore Existing
Please choose: 1

You are creating an xud node key and underlying wallets. All will be secured by
a single password provided below.

Enter a password:
Re-enter password:

Error: 14 UNAVAILABLE: lnd-LTC is Disconnected
Do you want to create a new xud environment or restore an existing one?
1) Create New
2) Restore Existing
Please choose: 1

You are creating an xud node key and underlying wallets. All will be secured by
a single password provided below.

Enter a password:
Re-enter password:

----------------------BEGIN XUD SEED---------------------
1. abandon 2. busy 3. canvas 4. join
5. mom 6. erode 7. always 8. lumber
9. sort 10. deer 11. coach 12. story
13. enhance 14. believe 15. fatal 16. oppose
17. home 18. chief 19. balcony 20. cave
21. bitter 22. maximum 23. frequent 24. want
-----------------------END XUD SEED----------------------

The following wallets were initialized: BTC, LTC, ERC20(ETH)

Please write down your 24 word mnemonic. It will allow you to recover your xud
node key and on-chain funds for the initialized wallets listed above should you
forget your password or lose your device. Off-chain funds in channels can NOT
be recovered with it and must be backed up and recovered separately. Keep it
somewhere safe, it is your ONLY backup in case of data loss.

YOU WILL NOT BE ABLE TO DISPLAY YOUR XUD SEED AGAIN. Press ENTER to continue...

Please enter a path to a destination where to store a backup of your environment. It includes everything, but NOT your wallet balance which is secured by your XUD SEED. The path should be an external drive, like a USB or network drive, which is permanently available on your device since backups are written constantly.

Enter path to backup location: ~/xud-testnet-backup
Checking backup location... OK.

.___ __ .__
___ _____ __ __| _/ _____/ |_| |
\ \/ / | \/ __ | _/ ___\ __\ |
> <| | / /_/ | \ \___| | | |__
/__/\_ \____/\____ | \___ >__| |____/
\/ \/ \/
--------------------------------------------------------------

testnet > status
┌───────────┬────────────────────────────────────────────────┐
│ SERVICE │ STATUS │
├───────────┼────────────────────────────────────────────────┤
│ bitcoind │ Ready (Connected to Neutrino) │
├───────────┼────────────────────────────────────────────────┤
│ litecoind │ Ready (Connected to Neutrino) │
├───────────┼────────────────────────────────────────────────┤
│ geth │ Ready (Connected to Infura) │
├───────────┼────────────────────────────────────────────────┤
│ lndbtc │ Waiting for sync │
├───────────┼────────────────────────────────────────────────┤
│ lndltc │ Waiting for sync │
├───────────┼────────────────────────────────────────────────┤
│ raiden │ Container running │
├───────────┼────────────────────────────────────────────────┤
│ xud │ Waiting for lndbtc, lndltc, raiden │
└───────────┴────────────────────────────────────────────────┘
testnet >
6 changes: 6 additions & 0 deletions tests/test_custom_network_dir/mainnet.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[bitcoind]
mode = "neutrino"
[litecoind]
mode = "neutrino"
[geth]
mode = "infura"
Loading