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

Feat/hip 729 #771

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 28 additions & 4 deletions contract_function_parameters_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ func TestUint160Max(t *testing.T) {
t.Parallel()
env := NewIntegrationTestEnv(t)
deployContract(env)
intType(t, env, "uint168", "1461501637330902918203684832716283019655932542975")
intType(t, env, "uint160", "1461501637330902918203684832716283019655932542975")
err := CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}
Expand Down Expand Up @@ -738,7 +738,7 @@ func TestUint184Max(t *testing.T) {
t.Parallel()
env := NewIntegrationTestEnv(t)
deployContract(env)
intType(t, env, "uint192", "24519928653854221733733552434404946937899825954937634815")
intType(t, env, "uint184", "24519928653854221733733552434404946937899825954937634815")
err := CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}
Expand Down Expand Up @@ -794,15 +794,15 @@ func TestUint216Min(t *testing.T) {
t.Parallel()
env := NewIntegrationTestEnv(t)
deployContract(env)
intType(t, env, "uint224", "0")
intType(t, env, "uint216", "0")
err := CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}
func TestUint216Max(t *testing.T) {
t.Parallel()
env := NewIntegrationTestEnv(t)
deployContract(env)
intType(t, env, "uint224", "105312291668557186697918027683670432318895095400549111254310977535")
intType(t, env, "uint216", "105312291668557186697918027683670432318895095400549111254310977535")
err := CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}
Expand Down Expand Up @@ -1781,3 +1781,27 @@ func TestBytes32Array(t *testing.T) {
err = CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}

func TestContractNonces(t *testing.T){
t.Parallel()
env := NewIntegrationTestEnv(t)
bytecode := []byte(`6080604052348015600f57600080fd5b50604051601a90603b565b604051809103906000f0801580156035573d6000803e3d6000fd5b50506047565b605c8061009483390190565b603f806100556000396000f3fe6080604052600080fdfea2646970667358221220a20122cbad3457fedcc0600363d6e895f17048f5caa4afdab9e655123737567d64736f6c634300081200336080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea264697066735822122053dfd8835e3dc6fedfb8b4806460b9b7163f8a7248bac510c6d6808d9da9d6d364736f6c63430008120033`)
fileCreate, err := NewFileCreateTransaction().
SetKeys(env.OperatorKey.PublicKey()).SetContents(bytecode).
Execute(env.Client)
require.NoError(t, err)
fileCreate.SetValidateStatus(true)
receipt, err := fileCreate.GetReceipt(env.Client)
require.NoError(t, err)
require.Equal(t, StatusSuccess, receipt.Status)
contractCreate, err := NewContractCreateTransaction().
SetBytecodeFileID(*receipt.FileID).
SetGas(10000000).Execute(env.Client)
require.NoError(t, err)
contractCreate.SetValidateStatus(true)
record,err:=contractCreate.GetRecord(env.Client)
require.NoError(t, err)
require.Equal(t, StatusSuccess, record.Receipt.Status)
require.Equal(t, int64(2), record.CallResult.ContractNonces[0].Nonce)
require.Equal(t, int64(1), record.CallResult.ContractNonces[1].Nonce)
}
10 changes: 10 additions & 0 deletions contract_function_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type ContractFunctionResult struct {
GasAvailable int64
Amount Hbar
FunctionParameters []byte
ContractNonces []*ContractNonceInfo
}

// GetBool gets a _Solidity bool from the result at the given index
Expand Down Expand Up @@ -474,6 +475,14 @@ func _ContractFunctionResultFromProtobuf(pb *services.ContractFunctionResult) Co
}
}

var nonces []*ContractNonceInfo
if len(pb.ContractNonces) > 0 {
nonces = make([]*ContractNonceInfo, len(pb.ContractNonces))
for i, nonce := range pb.ContractNonces {
nonces[i] = _ContractNonceInfoFromProtobuf(nonce)
}
}

result := ContractFunctionResult{
ContractCallResult: pb.ContractCallResult,
ErrorMessage: pb.ErrorMessage,
Expand All @@ -485,6 +494,7 @@ func _ContractFunctionResultFromProtobuf(pb *services.ContractFunctionResult) Co
GasAvailable: pb.Gas,
Amount: HbarFromTinybar(pb.Amount),
FunctionParameters: pb.FunctionParameters,
ContractNonces: nonces,
}

if pb.ContractID != nil {
Expand Down
43 changes: 43 additions & 0 deletions contract_nonce_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package hedera

/*-
*
* Hedera Go SDK
*
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import (
"github.com/hashgraph/hedera-protobufs-go/services"
)

// ContractID is the ID for a Hedera smart contract
type ContractNonceInfo struct {
ContractID *ContractID
Nonce int64
}

func _ContractNonceInfoFromProtobuf(contractNonceInfo *services.ContractNonceInfo) *ContractNonceInfo {
if contractNonceInfo == nil {
return nil
}

result := ContractNonceInfo{
ContractID: _ContractIDFromProtobuf(contractNonceInfo.GetContractId()),
Nonce: contractNonceInfo.GetNonce(),
}
return &result
}
31 changes: 31 additions & 0 deletions contract_nonce_info_unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build all || unit
// +build all unit

package hedera

import (
"testing"

"github.com/hashgraph/hedera-protobufs-go/services"
"github.com/stretchr/testify/assert"
)

func TestContractNonceInfoFromProtobuf(t *testing.T) {
contractID := &ContractID{Shard: 0, Realm: 0, Contract: 123}
nonce := int64(456)
protobuf := &services.ContractNonceInfo{
ContractId: contractID._ToProtobuf(),
Nonce: nonce,
}

result := _ContractNonceInfoFromProtobuf(protobuf)

assert.Equal(t, contractID, result.ContractID)
assert.Equal(t, nonce, result.Nonce)
}

func TestContractNonceInfoFromProtobuf_NilInput(t *testing.T) {
result := _ContractNonceInfoFromProtobuf(nil)

assert.Nil(t, result)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/ethereum/go-ethereum v1.12.0
github.com/hashgraph/hedera-protobufs-go v0.2.1-0.20230222133122-6549ac627de9
github.com/holiman/uint256 v1.2.3 // indirect
github.com/hashgraph/hedera-protobufs-go v0.2.1-0.20230620121835-2f2656b1f434
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.29.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4Zs
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w=
github.com/hashgraph/hedera-protobufs-go v0.2.1-0.20230222133122-6549ac627de9 h1:FcrKvjugTHGz5wZxdx6R/43EJwBDyal4paS+el+BXxc=
github.com/hashgraph/hedera-protobufs-go v0.2.1-0.20230222133122-6549ac627de9/go.mod h1:av0VF39ClcbPoUcDfMWnocYdjyPXKJJYB30h51fuuyg=
github.com/hashgraph/hedera-protobufs-go v0.2.1-0.20230620121835-2f2656b1f434 h1:zrc6tknD5Ry2lmED1mScl2THVMuLOAcRiUzl5v0qx+k=
github.com/hashgraph/hedera-protobufs-go v0.2.1-0.20230620121835-2f2656b1f434/go.mod h1:av0VF39ClcbPoUcDfMWnocYdjyPXKJJYB30h51fuuyg=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down