Skip to content

Commit

Permalink
Fix lazy_storage_diff issue | Ithaca endpoints (#289)
Browse files Browse the repository at this point in the history
* Fix lazy_storage_diff issue | Ithaca endpoints

* Fixup
  • Loading branch information
m-kus authored Mar 22, 2022
1 parent e4efc0a commit 49909fd
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 3.4.0 - 2022-03-22

### Fixed

* `run_code` does not merge lazy storage diffs correctly

### Changed

* Default protocol is Ithaca
* Sandbox node version is updated to v12

## 3.3.6 - 2022-03-10

### Fixed
Expand Down
7 changes: 3 additions & 4 deletions src/pytezos/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pytezos.operation.result import OperationResult
from pytezos.rpc.errors import RpcError
from pytezos.sandbox.node import DOCKER_IMAGE, TEZOS_NODE_PORT, SandboxedNodeContainer
from pytezos.sandbox.parameters import EDO, FLORENCE, HANGZHOU
from pytezos.sandbox.parameters import EDO, FLORENCE, HANGZHOU, ITHACA

kernel_js_path = join(dirname(dirname(__file__)), 'assets', 'kernel.js')
kernel_json = {
Expand Down Expand Up @@ -321,7 +321,7 @@ def smartpy_compile(

@cli.command(help='Run containerized sandbox node')
@click.option('--image', type=str, help='Docker image to use', default=DOCKER_IMAGE)
@click.option('--protocol', type=click.Choice(['edo', 'florence', 'hangzhou']), help='Protocol to use', default='hangzhou')
@click.option('--protocol', type=click.Choice(['hangzhou', 'ithaca']), help='Protocol to use', default='ithaca')
@click.option('--port', '-p', type=int, help='Port to expose', default=TEZOS_NODE_PORT)
@click.option('--interval', '-i', type=float, help='Interval between baked blocks (in seconds)', default=1.0)
@click.option('--blocks', '-b', type=int, help='Number of blocks to bake before exit')
Expand All @@ -335,9 +335,8 @@ def sandbox(
blocks: int,
):
protocol_hash = {
'edo': EDO,
'florence': FLORENCE,
'hangzhou': HANGZHOU,
'ithaca': ITHACA
}[protocol]

with SandboxedNodeContainer(image=image, port=port) as node:
Expand Down
3 changes: 2 additions & 1 deletion src/pytezos/context/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pytezos.rpc import RpcMultiNode, RpcNode, ShellQuery
from pytezos.rpc.errors import RpcError

default_network = 'hangzhounet'
default_network = 'ithacanet'
default_key = 'edsk33N474hxzA4sKeWVM6iuGNGDpX2mGwHNxEA4UbWS8sW3Ta3NKH' # please, use responsibly
default_key_hash = 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm'

Expand All @@ -29,6 +29,7 @@
'kaizen': ['https://rpc.tzkt.io/granadanet'],
'kaizennet': ['https://rpc.tzkt.io/granadanet'],
'hangzhounet': ['https://rpc.tzkt.io/hangzhou2net'],
'ithacanet': ['https://rpc.tzkt.io/ithacanet']
}
keys = {
'alice': alice_key,
Expand Down
2 changes: 1 addition & 1 deletion src/pytezos/contract/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def interpret(
res = {
'operations': operations,
'storage': storage,
'lazy_diff': lazy_diff,
'lazy_storage_diff': lazy_diff,
}
return ContractCallResult.from_run_code(
res,
Expand Down
2 changes: 1 addition & 1 deletion src/pytezos/contract/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def from_run_code(cls, response: Dict[str, Any], parameters, context: ExecutionC
program = MichelsonProgram.load(context)
parameters = program.parameter.from_parameters(parameters)
storage = program.storage.from_micheline_value(response['storage'])
extended_storage = storage.merge_lazy_diff(response.get('lazy_diff', []))
extended_storage = storage.merge_lazy_diff(response.get('lazy_storage_diff', []))
return cls(
parameters=parameters.to_python_object(),
storage=extended_storage.to_python_object(lazy_diff=True),
Expand Down
2 changes: 1 addition & 1 deletion src/pytezos/sandbox/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pytezos.operation.group import OperationGroup
from pytezos.sandbox.parameters import LATEST

DOCKER_IMAGE = 'bakingbad/sandboxed-node:v11.0-1'
DOCKER_IMAGE = 'bakingbad/sandboxed-node:v12.0-2'
MAX_ATTEMPTS = 100
ATTEMPT_DELAY = 0.1
TEZOS_NODE_PORT = 8732
Expand Down
3 changes: 2 additions & 1 deletion src/pytezos/sandbox/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
FLORENCE = 'PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i'
GRANADA = 'PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV'
HANGZHOU = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
ITHACA = 'Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A'
LATEST = HANGZHOU

protocol_version = {EDO: 8, FLORENCE: 9, GRANADA: 10, HANGZHOU: 11}
protocol_version = {EDO: 8, FLORENCE: 9, GRANADA: 10, HANGZHOU: 11, ITHACA: 12}

sandbox_commitment = {
"mnemonic": [
Expand Down
25 changes: 25 additions & 0 deletions tests/sandbox_tests/test_run_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pytezos.sandbox.node import SandboxedNodeTestCase
from pytezos import ContractInterface

code = """
{ parameter string ;
storage (big_map string nat) ;
code { UNPAIR ;
SWAP ;
PUSH nat 1 ;
SOME ;
DIG 2 ;
UPDATE ;
NIL operation ;
PAIR } }
"""


class TestRunCode(SandboxedNodeTestCase):

def test_lazy_storage_diff(self):
contract = ContractInterface.from_michelson(code).using(shell=self.client.shell)
res = contract.using('mainnet').default('hello').run_code()
self.assertEqual({'hello': 1}, res.storage)
res1 = contract.default('hello').interpret()
self.assertEqual({'hello': 1}, res1.storage)
2 changes: 1 addition & 1 deletion tests/unit_tests/test_contract/test_mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_transfer(self):
token_id=0)]) \
.interpret(storage=initial_storage_balance,
source=pkh)
self.assertTrue(len(res.lazy_diff), len(set(map(lambda x: x['id'], res.lazy_diff))))
self.assertEqual(len(res.lazy_diff), len(set(map(lambda x: x['id'], res.lazy_diff))))
self.assertDictEqual(
{
(pkh, 0): 41000,
Expand Down

0 comments on commit 49909fd

Please sign in to comment.