-
Notifications
You must be signed in to change notification settings - Fork 353
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
Problem: ibc solo machine integration not tested (fix #613) #757
Problem: ibc solo machine integration not tested (fix #613) #757
Conversation
Codecov Report
@@ Coverage Diff @@
## master #757 +/- ##
==========================================
- Coverage 20.02% 17.77% -2.25%
==========================================
Files 99 99
Lines 10966 10626 -340
==========================================
- Hits 2196 1889 -307
- Misses 8291 8297 +6
+ Partials 479 440 -39
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
sysstr = platform.system() | ||
if sysstr == "Darwin": | ||
url = "https://github.com/crypto-com/ibc-solo-machine/releases/\ | ||
download/v0.1.1/macos-latest-v0.1.1.tar.gz" | ||
self.sign_file = os.path.join(self.bin_dir, "libmnemonic_signer.dylib") | ||
else: | ||
url = "https://github.com/crypto-com/ibc-solo-machine/releases/\ | ||
download/v0.1.1/ubuntu-latest-v0.1.1.tar.gz" | ||
self.sign_file = os.path.join(self.bin_dir, "libmnemonic_signer.so") | ||
local_filename = url.split("/")[-1] | ||
tar_file = f"/tmp/{local_filename}" | ||
if os.path.exists(self.bin_file) and os.path.exists(self.sign_file): | ||
return | ||
with requests.get(url, allow_redirects=True, stream=True) as r: | ||
r.raise_for_status() | ||
with open(tar_file, "wb") as f: | ||
for chunk in r.iter_content(chunk_size=1024 * 8): | ||
f.write(chunk) | ||
# uncompress | ||
file = tarfile.open(tar_file) | ||
file.extractall(self.bin_dir) | ||
file.close() | ||
# check file exists | ||
if not os.path.exists(self.bin_file): | ||
raise Exception(f"solomachine binary file {self.bin_file} is not exists") | ||
if not os.path.exists(self.sign_file): | ||
raise Exception( | ||
f"solomachine signature file {self.sign_file} is not exists" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably ok, but it seems a bit cumbersome -- it can be replaced by having it fetched in the Nix environment (builtins.fetchTarball
) and having the solo machine binary in the environment's PATH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks all right, just two fixes to consider: 1) making the binary download more robust (e.g. by using Nix), 2) additional assertions against the node in the cluster
self.sign_file = os.path.join(self.bin_dir, "libmnemonic_signer.so") | ||
local_filename = url.split("/")[-1] | ||
tar_file = f"/tmp/{local_filename}" | ||
if os.path.exists(self.bin_file) and os.path.exists(self.sign_file): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably check the sha256 checksum of the binaries as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(or use Nix which will do it by default :))
builtins.fetchTarball {
url = "...";
sha256 = "...";
};
assert data["result"] == "success" | ||
data = solo_machine.add_chain() | ||
assert data["result"] == "success" | ||
time.sleep(3) | ||
solo_machine.connect_chain() | ||
time.sleep(3) | ||
balance_0 = int(solo_machine.get_balance()) | ||
assert balance_0 == 0 | ||
data = solo_machine.mint("0x20") | ||
assert data["result"] == "success" | ||
assert data["data"]["amount"] == "0x20" | ||
balance_1 = int(solo_machine.get_balance()) | ||
assert balance_1 == 0x20 | ||
time.sleep(3) | ||
data = solo_machine.burn("0x10") | ||
assert data["result"] == "success" | ||
assert data["data"]["amount"] == "0x10" | ||
time.sleep(3) | ||
balance_2 = int(solo_machine.get_balance()) | ||
assert balance_2 == balance_1 - 0x10 | ||
assert balance_1 > balance_2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some of these assertions should be against the node directly, i.e. to check that the chain/cluster node indeed received it (if there's a bug in the solo machine CLI or if it connects to a wrong node)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the PR to follow the C4 Spec?
A patch commit message MUST consist of a single short (less than 50 characters) line stating the problem (“Problem: …") being solved, followed by a blank line and then the proposed solution (“Solution: …").
d059b81
to
571d97c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the binary setup looks all right now.
there are two minor things to sort out:
- not hardcoding the environment config in the test
- checking and asserting on-chain denominations
I assume you've read contribution guidelines, so ideally you can also squash your commits after the changes and adjust the commit message as requested before.
- name: Tar debug files | ||
if: failure() | ||
run: tar cfz debug_files_solomachine.tar.gz -C /tmp/pytest-of-runner . | ||
- uses: actions/upload-artifact@v2 | ||
if: failure() | ||
with: | ||
name: debug_files_solomachine | ||
path: debug_files_solomachine.tar.gz | ||
if-no-files-found: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe ok, but are these debug files necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, same as other test settings.
def set_env(self): | ||
os.environ["SOLO_DB_URI"] = self.db_path | ||
os.environ["SOLO_SIGNER"] = self.sign_file | ||
os.environ[ | ||
"SOLO_MNEMONIC" | ||
] = "awesome there minute cash write immune tag \ | ||
reopen price congress trouble reunion south wisdom donate credit below leave \ | ||
wisdom eagle sail siege rice train" | ||
os.environ["SOLO_HD_PATH"] = "m/44'/394'/0'/0/0" | ||
os.environ["SOLO_ACCOUNT_PREFIX"] = "cro" | ||
os.environ["SOLO_ADDRESS_ALGO"] = "secp256k1" | ||
os.environ["SOLO_FEE_AMOUNT"] = "1000" | ||
os.environ["SOLO_FEE_DENOM"] = "basecro" | ||
os.environ["SOLO_GAS_LIMIT"] = "300000" | ||
os.environ["SOLO_GRPC_ADDRESS"] = f"http://0.0.0.0:{self.grpc_port}" | ||
os.environ["SOLO_RPC_ADDRESS"] = f"http://0.0.0.0:{self.rpc_port}" | ||
os.environ["SOLO_TRUSTED_HASH"] = self.trusted_hash | ||
os.environ["SOLO_TRUSTED_HEIGHT"] = self.trusted_height |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be taken from pystarport's yaml config instead of hardcoded here?
# fixme after this PR merged, currently only support hex string amount | ||
# https://github.com/crypto-com/ibc-solo-machine/pull/82 | ||
def mint(self, amount="0x20"): | ||
sub_cmd = f"ibc mint {self.chain_id} {amount} solotoken" | ||
return self.run_sub_cmd(sub_cmd) | ||
|
||
# fixme fix after this PR merged, currently only support hex string amount | ||
# https://github.com/crypto-com/ibc-solo-machine/pull/82 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the solo machine was upgraded to 0.1.2, so these comments can be removed and amounts can be passed in a decimal format?
# get the chain balance | ||
chain_solo_addr = cluster.address("solo-signer") | ||
chain_balance_1 = cluster.balance(chain_solo_addr) | ||
assert chain_balance_1 == 1500 * 10 ** 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the magic number can be extracted into a constant? e.g. CRO_DECIMALS = 10 ** 8
unless it's already defined somewhere else?
raise Exception(result) | ||
|
||
def get_balance(self): | ||
sub_cmd = f"chain balance {self.chain_id} solotoken" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess "solotoken" is the denomination? Can it be extracted into a constant or an argument/config parameter?
# check the chain balance | ||
chain_balance_2 = cli.balance(chain_solo_addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
besides checking the on-chain balance, it'll be good to assert the denomination is correct as well
36872b2
to
c55c070
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rebase against the latest master, given it's updated the ibc-go module?
os.environ[ | ||
"SOLO_MNEMONIC" | ||
] = "awesome there minute cash write immune tag \ | ||
reopen price congress trouble reunion south wisdom donate credit below leave \ | ||
wisdom eagle sail siege rice train" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why duplicate it in the test code and not take it from the test config ("solo_machine.yaml")?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix it.
807a62c
to
cbf1574
Compare
cbf1574
to
c02fda3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will merge, the other nits can be addressed in a future PR
No description provided.