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

native: implement StdLib and CryptoLib contracts #1824

Merged
merged 11 commits into from
Mar 10, 2021
Merged

Conversation

AnnaShaleva
Copy link
Member

@AnnaShaleva AnnaShaleva commented Mar 9, 2021

Close #1740

@codecov
Copy link

codecov bot commented Mar 9, 2021

Codecov Report

Merging #1824 (9015e50) into master (19a23a3) will increase coverage by 0.04%.
The diff coverage is 87.74%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1824      +/-   ##
==========================================
+ Coverage   83.42%   83.46%   +0.04%     
==========================================
  Files         283      281       -2     
  Lines       22194    22271      +77     
==========================================
+ Hits        18515    18589      +74     
+ Misses       2549     2545       -4     
- Partials     1130     1137       +7     
Impacted Files Coverage Δ
pkg/core/interop/crypto/interop.go 100.00% <ø> (ø)
pkg/core/interops.go 100.00% <ø> (ø)
pkg/core/native/designate.go 76.58% <ø> (ø)
pkg/core/native/ledger.go 92.92% <ø> (ø)
pkg/core/native/name_service.go 82.09% <ø> (ø)
pkg/core/native/native_gas.go 73.91% <ø> (ø)
pkg/core/native/native_neo.go 72.24% <ø> (ø)
pkg/core/native/oracle.go 76.89% <ø> (ø)
pkg/core/native/policy.go 86.62% <ø> (ø)
pkg/interop/crypto/crypto.go 0.00% <0.00%> (ø)
... and 20 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 19a23a3...9015e50. Read the comment docs.

Copy link
Contributor

@fyrchik fyrchik left a comment

Choose a reason for hiding this comment

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

Why are last 2 commits in this PR?

s.AddMethod(md, desc)

desc = newDescriptor("jsonSerialize", smartcontract.ByteArrayType,
manifest.NewParameter("data", smartcontract.AnyType))
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is "item".

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. I forgot about the names.

s.AddMethod(md, desc)

desc = newDescriptor("jsonDeserialize", smartcontract.AnyType,
manifest.NewParameter("data", smartcontract.ByteArrayType))
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is "json".

s.AddMethod(md, desc)

desc = newDescriptor("base64Decode", smartcontract.ByteArrayType,
manifest.NewParameter("data", smartcontract.StringType))
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is "s".

s.AddMethod(md, desc)

desc = newDescriptor("base58Decode", smartcontract.ByteArrayType,
manifest.NewParameter("data", smartcontract.StringType))
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is "s".

}

func (s *Std) atoi(_ *interop.Context, args []stackitem.Item) stackitem.Item {
numBytes, err := args[0].TryBytes()
Copy link
Contributor

Choose a reason for hiding this comment

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

toString(args[0]) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here and in all other places.

panic(fmt.Errorf("invalid value stackitem: %w", err))
}
num := string(numBytes)
base, err := args[1].TryInteger()
Copy link
Contributor

Choose a reason for hiding this comment

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

toBigInt(args[1]) ?

import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
func Main() int {
sum := 0
values := []int{10, 11}
for _, v := range values {
binary.Itoa(v, 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

It needs to be replaced with another syscall returning some value (Notify returns nothing).

import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
func Main() int {
sum := 0
values := []int{10, 11}
for _, v := range values {
binary.Itoa(v, 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
func Main() int {
sum := 0
values := []int{10, 11}
for _, v := range values {
binary.Itoa(v, 10)
sum += inline.VarSum(1, 2, 3, binary.Atoi("4", 10))
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we need some syscall which returns integer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced with runtime.GetTime.

import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
func Main() int {
values := []int{10, 11, 12}
for _, v := range values {
binary.Itoa(v, 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, it was here because it's returned value is dropped.

import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
func Main() int {
sum := 0
values := []int{10, 11}
for _, v := range values {
binary.Itoa(v, 10)
sum += inline.VarSum(1, 2, 3, 4)
if v != 0 { // use 'v'
Copy link
Contributor

Choose a reason for hiding this comment

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

if creates another scope. We better just use e.g. _ = v.

@AnnaShaleva
Copy link
Member Author

Why are last 2 commits in this PR?

They were in neo-modules#517 along with the changes related to this PR. Removed them.

@AnnaShaleva AnnaShaleva force-pushed the native/libs branch 2 times, most recently from 413dbe7 to 75c65c3 Compare March 10, 2021 11:45
Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

Looks like native contract coverage can be improved for erroneous cases.

pkg/interop/native/crypto/crypto.go Outdated Show resolved Hide resolved
pkg/core/native/contract.go Outdated Show resolved Hide resolved
pkg/core/native/std.go Outdated Show resolved Hide resolved
pkg/core/notary_test.go Outdated Show resolved Hide resolved
pkg/crypto/keys/private_key_test.go Outdated Show resolved Hide resolved
pkg/interop/crypto/crypto.go Outdated Show resolved Hide resolved
@AnnaShaleva AnnaShaleva force-pushed the native/libs branch 2 times, most recently from 30e149e to e4ce23a Compare March 10, 2021 16:23
@roman-khimov
Copy link
Member

They were in neo-modules#517 along with the changes related to this PR.

Another PR for them?

pkg/crypto/keys/nep2_test.go Outdated Show resolved Hide resolved
@roman-khimov roman-khimov requested a review from fyrchik March 10, 2021 18:22
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.

Native stdlib and cryptolib contracts
3 participants