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

1.4.0 - Upgrade to grpc gateway endpoints #22

Merged
merged 52 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7a060e2
Add 1.4.0 proto
Oct 10, 2022
eae364b
Refactor encryption utils into a standalone class that doesnt inherit…
paul-HDD Oct 10, 2022
4d748ef
fix shit & add test
paul-HDD Oct 10, 2022
61641d0
Integration test for sign direct
paul-HDD Oct 10, 2022
60e863d
grpc gateway migration, interface proto, amino
Oct 10, 2022
df824c7
Fix conflicts
Oct 10, 2022
d627cb7
terra to scrt
paul-HDD Oct 10, 2022
7456448
Fix merge conflig on encrypt utils
paul-HDD Oct 10, 2022
42a1cd8
Add registration api
Oct 10, 2022
fbeb740
Merge branch 'grpc_gateway' of https://github.com/secretanalytics/sec…
Oct 10, 2022
4f86ec1
Fix get consensus pub key
paul-HDD Oct 11, 2022
6906bae
Refactoring of encrypt utils, changing signature of to_proto to accou…
paul-HDD Oct 11, 2022
77772bf
Upgrade tx, wallet, signing
paul-HDD Oct 11, 2022
d7608b0
More stuff
paul-HDD Oct 11, 2022
b9ead83
Fixing wallet send_token and execute_tx integration
paul-HDD Oct 11, 2022
2926e1a
Add execute_tx integration test, finalize contract execute
paul-HDD Oct 11, 2022
feccc22
Fix secret contract query
paul-HDD Oct 11, 2022
f6b0bd7
Add query by block height, fix contract hash caching
paul-HDD Oct 11, 2022
0b47c2c
Add integration test query contract
paul-HDD Oct 11, 2022
b29f91d
Spring cleaning
paul-HDD Oct 15, 2022
61d0ff7
Remove block height as arg of function, nest it into params
paul-HDD Oct 15, 2022
30193c0
Add time out & retries
paul-HDD Oct 15, 2022
61176af
Add execute / multi execute
paul-HDD Oct 15, 2022
4996462
Fix mnemonic test
paul-HDD Oct 15, 2022
3df3c36
Fix conflicts + use create_and_broadcast in send_tokens + default gas…
Oct 15, 2022
4a57097
gas adjustement default, small fix in lcdclient
Oct 15, 2022
472539a
Add multiSend, add send, multisend test using localsecret
Oct 15, 2022
235df55
revert MakeFile
Oct 15, 2022
47b76f3
Fix test, clean shit
paul-HDD Oct 15, 2022
d690926
Spring cleaningzer
paul-HDD Oct 16, 2022
38aa664
add gzip to MsgStoreCode
Oct 16, 2022
439e729
Add ModuleAccount, accounts endpoint, testing
Oct 16, 2022
a582ae0
Add pytest, configure test, account_info test
Oct 16, 2022
8fa3fd9
spring cleaning
paul-HDD Oct 16, 2022
c12d4bb
Fix search tx
Oct 16, 2022
d38add9
Merge branch 'grpc_gateway' of https://github.com/secretanalytics/sec…
Oct 16, 2022
e607269
Add Params, params test
Oct 16, 2022
ed993d6
final spring cleanup
paul-HDD Oct 16, 2022
a0a172a
Add snip20-ibc + snip721 contracts for testing
Oct 16, 2022
6369c05
Merge branch 'grpc_gateway' of https://github.com/secretanalytics/sec…
Oct 16, 2022
6496473
StoreCode, TxResultCode, 9090 port to localsecret(
Oct 16, 2022
45ce751
Fix code info by code id endpoint
Oct 16, 2022
0205001
Fix MsgInstantiatContract, add instantiate test
Oct 16, 2022
049d99f
Fixing tx decrypt & adding height from get request headers
paul-HDD Oct 16, 2022
8e3947a
Fix decrypt tx on broadcast, search, added get tx, more tests on exec…
Nov 5, 2022
211d0c2
Add contract query test
Nov 5, 2022
fdbb34b
Clean tests, fix mnemonic key
Nov 6, 2022
a4b63ae
Fix json log decrypt parsing on errors and test
Nov 6, 2022
6971df9
Move local chain tests to pytest
Nov 6, 2022
5bf00e4
Merge branch 'main' into grpc_gateway
Nov 6, 2022
6eb98b1
1.4.0
Nov 6, 2022
e978704
1.4.0
Nov 6, 2022
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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "secret.proto"]
path = secret.proto
url = https://github.com/stephanegg/secret.proto
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
author = "SCRT LabRador, Secret analytics"

# The full version, including alpha/beta/rc tags
release = "1.0.0"
release = "1.4.0"


# -- General configuration ---------------------------------------------------
Expand Down
99 changes: 51 additions & 48 deletions integration_tests/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from secret_sdk.client.localsecret import LocalSecret, main_net_chain_id
from secret_sdk.client.lcd.api.tx import CreateTxOptions

secret = LocalSecret(chain_id=main_net_chain_id)

Expand All @@ -12,15 +13,15 @@
print("---------------------------")

print("Bank")
res = secret.bank.balance(binance_account)
res, _ = secret.bank.balance(binance_account)
print(res)
print("---------------------------")

print("Distribution")
res = secret.distribution.rewards(delegator_address)
print(res)

res = secret.distribution.validator_rewards(validator_address)
res = secret.distribution.validator_outstanding_rewards(validator_address)
print(res)

res = secret.distribution.withdraw_address(delegator_address)
Expand All @@ -44,18 +45,18 @@
)
print(res)

res = secret.staking.unbonding_delegations(validator=validator_address)
print(res)
res = secret.staking.unbonding_delegations(delegator=delegator_address)
print(res)
res, pagination = secret.staking.unbonding_delegations(validator=validator_address)
print(res, pagination)
res, pagination = secret.staking.unbonding_delegations(delegator=delegator_address)
print(res, pagination)

res = secret.staking.redelegations()
print(res)
#res = secret.staking.redelegations()
#print(res)
res = secret.staking.redelegations(delegator=delegator_address)
print(res)
res = secret.staking.redelegations(validator_src=validator_address)
res = secret.staking.redelegations(delegator=delegator_address, validator_src=validator_address)
print(res)
res = secret.staking.redelegations(validator_dst=validator_address)
res = secret.staking.redelegations(delegator=delegator_address, validator_dst=validator_address)
print(res)

res = secret.staking.bonded_validators(delegator=delegator_address)
Expand All @@ -81,17 +82,13 @@
res = secret.tendermint.syncing()
print(res)

res = secret.tendermint.syncing()
print(res)

res = secret.tendermint.block_info()
print(res)

last_block = int(secret.tendermint.block_info()["block"]["header"]["height"])

res = secret.tendermint.block_info(last_block - 10)
print(res)

# res = secret.tendermint.block_info(last_block - 10)
# print(res)

res = secret.tendermint.validator_set()
print(res)
Expand All @@ -102,42 +99,49 @@

print("Tx")
for tx_hash in [
"E9557807CE4CE6E387059523D6ED716B0F59BFE0B5E4DD998B8BB026747C320C",
"259DA3D4807CA31A8C2FFBD3F0D6DAFF6B5F1F914F10C3E52456B10D06BF3A96",
"1DB6541E7047B0BAB52287FA5967D87BF188E36E66B15517CA89283180BB6797",
"7CE39254CF20AE08D220D8B0D0627E9ABB5B688FFEFC6838B1E96B1182C442F8",
"9195E398AB2B0BEEE9499594AC14431D898386ADFEFDF12BEC0E5114C360641B",
"51E777E2A57CD61D15FEA1A63991E9A0E3D6613CA3A6BDDEEC4AC2C48B9B6844",
"BE769AFDC968532903A3598816EFEC839E984F91DFAA99007F24B106B31F7146",
"01E86971C548E05AB3B2239FB506C4818BC11EC769186E02BC67A068C91FFD98",
"79F65CD9205327BD3F49951D53E5D9AF492D7FFB8A5EFABB662DDA7B4DC99559",
# withdrew rewards
"ADB467AC82074C9C62C78160FED9D27ACAD9EAF268A6EFEFF11B317D9EA24D53",
# IBC Transfer
"ADB467AC82074C9C62C78160FED9D27ACAD9EAF268A6EFEFF11B317D9EA24D53",
# Vote Yes
"B0B1E71BEC2C936AF8AF4050A4985662D980698355ED17C1E3209562F4DA571C",
# Execute contract
"64CA905571B619BE6DF3560978E599A8850ADC6ADF941AD79E83CB7A22798BF8",
# Delegate
"2F2712E4D811F8B518E28CC36E2C2684CEF3447B63712E608F5C8FEAA5B431DE",
# Execute contract
"EB9AF0ED433ED638BC7048E11F7B07EF7AFE14B6672D066DB26235628BB88692",
# Execute contract
"A59E9E6335E7F07268B866358EB81E129D904A66BF9C5D8BA6B7494BBC0A76A2",
# IBC Update client
"C16E1FD7CAC31FBBDD4FCD214651946DA87610DEAE8CFC978DA8601EA71772A2",
# Unbond
"171E61D11615374977738E85AD6AAF5DD7CA0E55216DA9B12571B85539B08566",
# Delegate
"E83672197CCF91516C4E672212424A0B7BB941F4581DE86150C716DA12F99E3C",
# Send
"F5D2D87769EF8AB0590F0CBA173A155005ABAE9ADACE57A7E92CE122C5331392"
]:
try:
res = secret.tx.tx_info(tx_hash)
print(res)
# print(res)
except Exception as e:
print(e)
print(tx_hash, e)

try:
res = secret.tx.tx_by_id(tx_hash)
print(res)
except Exception as e:
print(e)
opt = CreateTxOptions(msgs = [])
res = secret.tx.estimate_fee(
opt
)
print(res)


res = secret.tx.search(
events = [
["tx.height", 5599260],
])

print(res)

# res = secret.tx.estimate_fee(
# sender=delegator_address,
# msgs=[],
# memo=''
# )
# print(res)
# encode(tx: StdTx, options: BroadcastOptions = None)
# hash(tx: StdTx)
# _broadcast(tx: StdTx, mode: str, options: BroadcastOptions = None)
# broadcast_sync(tx: StdTx, options: BroadcastOptions = None)
# broadcast_async(tx: StdTx, options: BroadcastOptions = None)
# broadcast(tx: StdTx, options: BroadcastOptions = None)

secret.tx.search(options={"tx.height": 1781786})
print("---------------------------")

print("Wasm")
Expand All @@ -149,8 +153,6 @@
)
print(res)

res = secret.wasm.contract_hash_by_code_id(code_id=5)
print(res)

res = secret.wasm.contract_hash("secret1k0jntykt7e4g3y88ltc60czgjuqdy4c9e8fzek")
print(res)
Expand All @@ -162,6 +164,7 @@

isFullNode = False
if isFullNode:
last_block = int(secret.tendermint.block_info()["block"]["header"]["height"])
res = secret.wasm.contract_query(
contract_address="secret1rgky3ns9ua09rt059049yl0zqf3xjqxne7ezhp",
query={"pool": {}},
Expand Down
38 changes: 13 additions & 25 deletions integration_tests/estimate_fee.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
from secret_sdk.core import Coins
from secret_sdk.client.lcd.api.tx import CreateTxOptions
from secret_sdk.client.localsecret import LocalSecret, main_net_chain_id

api = LocalSecret(chain_id=main_net_chain_id)
fee = api.tx.estimate_fee(
gas=250_000
)
print(fee)

fee = api.tx.estimate_fee(
gas=200_000,
gas_prices=Coins.from_data([{"amount": 0.25, "denom": "uscrt"}])
)
print(fee)
options_to_test =[
CreateTxOptions(msgs=[], gas='250000'),
CreateTxOptions(msgs=[], gas='200000', gas_prices=Coins('0.25uscrt')),
CreateTxOptions(msgs=[], gas='200000', gas_prices=Coins('0.25uscrt'), gas_adjustment=1.2),
CreateTxOptions(msgs=[], gas='200000', gas_prices=Coins('0.25uscrt'), fee_denoms=['ukrw']) # return nothing

fee = api.tx.estimate_fee(
gas=200_000,
gas_prices=Coins.from_data([{"amount": 0.25, "denom": "uscrt"}]),
gas_adjustment=1.2,
fee_denoms=["uscrt"]
)
print(fee)

fee = api.tx.estimate_fee(
gas=200_000,
gas_prices=Coins.from_data([{"amount": 0.25, "denom": "uscrt"}]),
fee_denoms=["ukrw"]
)
print(fee)
]
api = LocalSecret(chain_id=main_net_chain_id)
for opt in options_to_test:
fee = api.tx.estimate_fee(
opt
)
print(fee)
12 changes: 12 additions & 0 deletions integration_tests/execute_tx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from secret_sdk.client.localsecret import LocalSecret, main_net_chain_id, test_net_chain_id
from secret_sdk.core.coins import Coins

secret = LocalSecret(chain_id=test_net_chain_id)

w = secret.wallets['test1']
sscrt_addr_testnet = 'secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg'
sent_funds = Coins('100uscrt')
handle_msg = {'deposit': {}}
t = w.execute_tx(sscrt_addr_testnet, handle_msg, transfer_amount=sent_funds)

assert t.code == 0
8 changes: 4 additions & 4 deletions integration_tests/from_contract_events.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from integration_tests.config import api_url
from secret_sdk.client.lcd import LCDClient
from secret_sdk.util.contract import get_contract_events

api = LCDClient(url=api_url, chain_id="secret-4")
tx_info = api.tx.tx_info(
from secret_sdk.client.localsecret import LocalSecret, main_net_chain_id

secret = LocalSecret(chain_id=main_net_chain_id)
tx_info = secret.tx.tx_info(
"9F90D988CE4569CAB07AC0331E188AD873FCAAA21B9701FB8705AE6053620C72"
)
print(get_contract_events(tx_info))
5 changes: 0 additions & 5 deletions integration_tests/lcdutils.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def main():
secret = LocalSecret(chain_id=main_net_chain_id)

result = secret.bank.balance(
result, pagination = secret.bank.balance(
address="secret19y0n2ru9dae9w6vt7fwgfptp5nxq3hwtsz4u75"
)
print(result)
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/query_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from secret_sdk.client.localsecret import LocalSecret, main_net_chain_id, test_net_chain_id
from secret_sdk.core.coins import Coins

secret = LocalSecret(chain_id=main_net_chain_id)
contract = 'secret1rgky3ns9ua09rt059049yl0zqf3xjqxne7ezhp'
hash = '0dfd06c7c3c482c14d36ba9826b83d164003f2b0bb302f222db72361e0927490'
query = {"pool":{}}
height = 5589677
a = secret.wasm.contract_query(contract, query, timeout=30)
b = secret.wasm.contract_query(contract, query, height=height, timeout=30)
assert a['assets'][0]['amount'] != b['assets'][0]['amount']
6 changes: 2 additions & 4 deletions integration_tests/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
secret = LocalSecret(chain_id=test_net_chain_id)
test1 = secret.wallets["test1"]

print(test1)

result = test1.send_tokens(
test1.key.acc_address,
LOCAL_MNEMONICS[test_net_chain_id]["test2"]["address"],
Coins.from_str("1000000uscrt"),
Coins.from_str("1uscrt"),
gas=250_000,
)
print(result)
assert result.code == 0
92 changes: 92 additions & 0 deletions integration_tests/sign_direct_via_pb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from secret_sdk.client.localsecret import LocalSecret, main_net_chain_id, test_net_chain_id
from secret_sdk.util.address_converter import address_to_bytes
import json
import base64
import requests
from secret_sdk.protobuf.cosmos.crypto.ed25519 import PubKey
from betterproto.lib.google.protobuf import Any as Any_pb

from secret_sdk.protobuf.secret.compute.v1beta1 import MsgExecuteContract as MsgExecuteContract_pb
from secret_sdk.protobuf.cosmos.bank.v1beta1 import MsgSend
from secret_sdk.protobuf.cosmos.tx.v1beta1 import Tx as Tx_pb, TxBody as TxBody_pb, AuthInfo as AuthInfo_pb, \
SignDoc as SignDoc_pb, SignerInfo as SignerInfo_pb, ModeInfo as ModeInfo_pb, ModeInfoSingle as ModeInfoSingle_pb

from secret_sdk.protobuf.cosmos.tx.signing.v1beta1 import SignMode
from secret_sdk.protobuf.cosmos.tx.v1beta1 import Fee
from secret_sdk.protobuf.cosmos.base.v1beta1 import Coin as Coin_pb


secret = LocalSecret(chain_id=test_net_chain_id)
wallet = secret.wallets['test1']
wallet_end = secret.wallets['test2']
chain_id = test_net_chain_id
acc_addr = wallet.key.acc_address
mnemonic_key = wallet.key

# msg send
msg_send = MsgSend(wallet.key.acc_address, wallet_end.key.acc_address, amount = [Coin_pb('uscrt', '100')])


# encrypt msg
sscrt_addr_testnet = 'secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg'
sent_funds = [Coin_pb('uscrt', '100')]
handle_msg = {'deposit': {}}
contract_code_hash = '9587D60B8E6B078ACE12014CEEEE089530B9FABCD76535D93666A6C127AD8813'
msg_str = json.dumps(handle_msg, separators=(",", ":"))
encrypted_msg = bytes(secret.encrypt_utils.encrypt(contract_code_hash, msg_str))

msg = MsgExecuteContract_pb(
sender = address_to_bytes(acc_addr),
contract = address_to_bytes(sscrt_addr_testnet),
msg = encrypted_msg,
sent_funds = sent_funds
)

# create tx
def create_tx(msg, type_url):
wrap_msg = Any_pb(type_url=type_url, value=bytes(msg))
tx_body = TxBody_pb([wrap_msg], memo='', timeout_height=0)
# fee = Fee([Coin('uluna', '9480')], 63199, "", "")
fee = Fee([Coin_pb('uscrt', '94800')], gas_limit=163199, payer="", granter="")
auth_info = AuthInfo_pb([], fee)
tx = Tx_pb(tx_body, auth_info, signatures=[])
return tx

def sign_tx(tx):
account_number = wallet.account_number()
sequence = wallet.sequence()

public_key = Any_pb(type_url='/cosmos.crypto.secp256k1.PubKey', value=bytes(wallet.key.public_key.to_proto()))
mode_info = ModeInfo_pb(
single=ModeInfoSingle_pb(mode=SignMode.SIGN_MODE_DIRECT)
)
tx.auth_info.signer_infos = [
SignerInfo_pb(
public_key=public_key,
sequence=sequence,
mode_info=mode_info
)
]

signDoc = SignDoc_pb(
chain_id=chain_id,
account_number=account_number,
auth_info_bytes=bytes(tx.auth_info),
body_bytes=bytes(tx.body),
)
signDoc_payload = bytes(signDoc)
signed_signDoc = wallet.key.sign(signDoc_payload)

tx.signatures.append(signed_signDoc)

send_tx = create_tx(msg_send, type_url='/cosmos.bank.v1beta1.MsgSend')
sign_tx(send_tx)
send_tx_bytes = base64.b64encode(bytes(send_tx)).decode()
# send_tx_res = requests.post(f"{secret.url}/cosmos/tx/v1beta1/txs", json= {'tx_bytes':send_tx_bytes, "mode":'BROADCAST_MODE_BLOCK'})
# print(send_tx_res.json())

sscrt_tx = create_tx(msg, type_url='/secret.compute.v1beta1.MsgExecuteContract')
sign_tx(sscrt_tx)
sscrt_tx_bytes = base64.b64encode(bytes(sscrt_tx)).decode()
r = requests.post(f"{secret.url}/cosmos/tx/v1beta1/txs", json= {'tx_bytes':sscrt_tx_bytes, "mode":'BROADCAST_MODE_BLOCK'})
print(r.json())
Loading