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

Problem: ibc solo machine integration not tested (fix #613) #757

Merged
merged 1 commit into from
May 17, 2022

Conversation

linfeng-crypto
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Apr 27, 2022

Codecov Report

Merging #757 (571d97c) into master (ef0bb6d) will decrease coverage by 2.24%.
The diff coverage is n/a.

❗ Current head 571d97c differs from pull request most recent head c02fda3. Consider uploading reports for the commit c02fda3 to get more accurate results

@@            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     
Flag Coverage Δ
integration_tests 17.77% <ø> (-0.01%) ⬇️
unit_tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
x/icaauth/types/types.go 0.00% <0.00%> (-100.00%) ⬇️
x/nft/keeper/owners.go 17.02% <0.00%> (-68.09%) ⬇️
x/nft/keeper/grpc_query.go 12.50% <0.00%> (-53.75%) ⬇️
x/nft/keeper/collection.go 23.18% <0.00%> (-49.28%) ⬇️
x/nft/keeper/nft.go 51.85% <0.00%> (-48.15%) ⬇️
x/nft/types/msgs.go 7.40% <0.00%> (-40.75%) ⬇️
x/nft/client/cli/query.go 33.51% <0.00%> (-35.20%) ⬇️
x/nft/keeper/denom.go 51.28% <0.00%> (-33.34%) ⬇️
x/nft/client/cli/tx.go 43.75% <0.00%> (-32.30%) ⬇️
x/icaauth/types/message_register_account.go 0.00% <0.00%> (-26.67%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef0bb6d...c02fda3. Read the comment docs.

Comment on lines 77 to 105
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"
)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor

@tomtau tomtau left a 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):
Copy link
Contributor

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

Copy link
Contributor

@tomtau tomtau Apr 27, 2022

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 = "...";
  };

Comment on lines 162 to 182
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
Copy link
Contributor

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)

Copy link
Collaborator

@devashishdxt devashishdxt left a 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: …").

@tomtau tomtau requested a review from macong-cdc May 10, 2022 03:00
@linfeng-crypto linfeng-crypto force-pushed the test_solo_machine branch 2 times, most recently from d059b81 to 571d97c Compare May 12, 2022 10:04
Copy link
Contributor

@tomtau tomtau left a 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:

  1. not hardcoding the environment config in the test
  2. 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.

Comment on lines +114 to +122
- 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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 67 to 91
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
Copy link
Contributor

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?

Comment on lines 117 to 124
# 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
Copy link
Contributor

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
Copy link
Contributor

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"
Copy link
Contributor

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?

Comment on lines 165 to 169
# check the chain balance
chain_balance_2 = cli.balance(chain_solo_addr)
Copy link
Contributor

@tomtau tomtau May 13, 2022

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

@linfeng-crypto linfeng-crypto force-pushed the test_solo_machine branch 4 times, most recently from 36872b2 to c55c070 Compare May 16, 2022 08:51
Copy link
Contributor

@tomtau tomtau left a 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?

Comment on lines 77 to 81
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"
Copy link
Contributor

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")?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it.

@linfeng-crypto linfeng-crypto force-pushed the test_solo_machine branch 6 times, most recently from 807a62c to cbf1574 Compare May 16, 2022 10:12
Copy link
Contributor

@tomtau tomtau left a 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

@tomtau tomtau changed the title add ibc solo machine integration(fix #613) Problem: ibc solo machine integration not tested (fix #613) May 17, 2022
@tomtau tomtau merged commit 3fdc974 into crypto-org-chain:master May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants