Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Aug 4, 2020
1 parent 86151d5 commit e266095
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions neo3/contracts/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def to_json(self) -> dict:
"""
json = super(ContractMethodDescriptor, self).to_json()
json.update({
"returnType": self.return_type.name.title()
"returntype": self.return_type.name.title()
})
return json

Expand All @@ -177,7 +177,7 @@ def from_json(cls, json: dict) -> ContractMethodDescriptor:
return cls(
name=json['name'],
parameters=list(map(lambda p: contracts.ContractParameterDefinition.from_json(p), json['parameters'])),
return_type=contracts.ContractParameterType[json['returnType'].upper()]
return_type=contracts.ContractParameterType[json['returntype'].upper()]
)


Expand Down
8 changes: 4 additions & 4 deletions neo3/contracts/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def to_json(self) -> dict:
Convert object into JSON representation.
"""
json = {
'pubKey': str(self.public_key),
'pubkey': str(self.public_key),
'signature': base64.b64encode(self.signature).decode()
}
return json
Expand All @@ -57,7 +57,7 @@ def from_json(cls, json: dict) -> ContractGroup:
KeyError: if the data supplied does not contain the necessary keys.
"""
return cls(
public_key=cryptography.EllipticCurve.ECPoint.deserialize_from_bytes(binascii.unhexlify(json['pubKey'])),
public_key=cryptography.EllipticCurve.ECPoint.deserialize_from_bytes(binascii.unhexlify(json['pubkey'])),
signature=base64.b64decode(json['signature'].encode('utf8'))
)

Expand Down Expand Up @@ -341,7 +341,7 @@ def _deserialize_from_json(self, json: dict) -> None:
lambda t: types.UInt160.from_string(t))

# converting json key/value back to default WildcardContainer format
self.safe_methods = WildcardContainer.from_json({'wildcard': json['safeMethods']})
self.safe_methods = WildcardContainer.from_json({'wildcard': json['safemethods']})
self.extra = json['extra']

def to_json(self) -> dict:
Expand All @@ -358,7 +358,7 @@ def to_json(self) -> dict:
"abi": self.abi.to_json(),
"permissions": list(map(lambda p: p.to_json(), self.permissions)),
"trusts": trusts,
"safeMethods": self.safe_methods.to_json()['wildcard'],
"safemethods": self.safe_methods.to_json()['wildcard'],
"extra": self.extra
}
return json
Expand Down
8 changes: 4 additions & 4 deletions tests/contracts/test_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def setUpClass(cls) -> None:
cls.parameters = [contracts.ContractParameterDefinition("param", contracts.ContractParameterType.STRING)]
cls.expected = {"name": "MainMethod",
"parameters": [cls.parameters[0].to_json()],
"returnType": "Boolean"}
"returntype": "Boolean"}

def test_default_entry_point(self):
cmd = contracts.ContractMethodDescriptor.default_entrypoint()
Expand All @@ -98,9 +98,9 @@ def test_from_json(self):

with self.assertRaises(KeyError) as context:
json_without_return_type = self.expected.copy()
json_without_return_type.pop('returnType')
json_without_return_type.pop('returntype')
contracts.ContractMethodDescriptor.from_json(json_without_return_type)
self.assertIn('returnType', str(context.exception))
self.assertIn('returntype', str(context.exception))

def test_eq(self):
cmd = contracts.ContractMethodDescriptor.from_json(self.expected)
Expand Down Expand Up @@ -146,7 +146,7 @@ def setUpClass(cls) -> None:
)
cls.events = [cls.event]
# captured from C#
cls.expected_json = {"hash": "0x0000000000000000000000000000000000000000","entryPoint":{"name":"Main","parameters":[{"name":"operation","type":"String"},{"name":"args","type":"Array"}],"returnType":"Any"},"methods":[{"name":"main_entry","parameters":[],"returnType":"Integer"}],"events":[{"name":"main_event","parameters":[]}]}
cls.expected_json = {"hash": "0x0000000000000000000000000000000000000000","entryPoint":{"name":"Main","parameters":[{"name":"operation","type":"String"},{"name":"args","type":"Array"}],"returntype":"Any"},"methods":[{"name":"main_entry","parameters":[],"returntype":"Integer"}],"events":[{"name":"main_event","parameters":[]}]}

def test_to_json(self):
abi = contracts.ContractABI(
Expand Down
6 changes: 3 additions & 3 deletions tests/contracts/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setUpClass(cls) -> None:
cls.keypair = cryptography.KeyPair(private_key)

# capture from C#
cls.expected_json = {'pubKey': '033d523f36a732974c0f7dbdfafb5206ecd087211366a274190f05b86d357f4bad', 'signature': 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='}
cls.expected_json = {'pubkey': '033d523f36a732974c0f7dbdfafb5206ecd087211366a274190f05b86d357f4bad', 'signature': 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='}

def test_is_valid(self):
"""
Expand Down Expand Up @@ -213,7 +213,7 @@ def setUpClass(cls) -> None:
Console.WriteLine(cm.ToJson());
Console.WriteLine(cm.Size);
"""
cls.expected_json = {"groups":[],"features":{"storage":False,"payable":False},"abi":{"hash":"0x0000000000000000000000000000000000000000","entryPoint":{"name":"Main","parameters":[{"name":"operation","type":"String"},{"name":"args","type":"Array"}],"returnType":"Any"},"methods":[],"events":[]},"permissions":[{"contract":"*","methods":"*"}],"trusts":[],"safeMethods":[],"extra":None}
cls.expected_json = {"groups":[],"features":{"storage":False,"payable":False},"abi":{"hash":"0x0000000000000000000000000000000000000000","entryPoint":{"name":"Main","parameters":[{"name":"operation","type":"String"},{"name":"args","type":"Array"}],"returntype":"Any"},"methods":[],"events":[]},"permissions":[{"contract":"*","methods":"*"}],"trusts":[],"safemethods":[],"extra":None}

def test_create_default(self):
cm = contracts.ContractManifest(types.UInt160.zero())
Expand All @@ -240,7 +240,7 @@ def test_to_json_with_trusts_safemethods_extra(self):

self.assertIn("0x" + str(t1), json_out['trusts'])
self.assertIn("0x" + str(t2), json_out['trusts'])
self.assertIn("safe1", json_out['safeMethods'])
self.assertIn("safe1", json_out['safemethods'])
self.assertFalse(json_out['extra'])

def test_from_json(self):
Expand Down

0 comments on commit e266095

Please sign in to comment.