Skip to content

Commit

Permalink
Merge pull request #34 from make-software/feature/CMW-329/node_types_v3
Browse files Browse the repository at this point in the history
Add fully compatible with Node Types v3.0
  • Loading branch information
koltsov-iv authored Jul 18, 2023
2 parents f692204 + b683e70 commit 6a8b30e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rpc/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
type RpcError struct {
Code int `json:"code"`
Message string `json:"message"`
Data string `json:"data,omitempty"`
}

func (h *RpcError) Error() string {
return h.Message
return fmt.Sprintf("key: %s, data: %s", h.Message, h.Data)
}

type HttpError struct {
Expand Down
3 changes: 2 additions & 1 deletion tests/data/contract/contract_package_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"group": "constructor",
"keys": []
}
]
],
"lock_status": "Unlocked"
}
3 changes: 3 additions & 0 deletions tests/data/keys/docker-nctl-secret.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIBUARqE05TYBPqqYe4Yi6YXBsYOuLA3lhFSquB21JY5q
-----END PRIVATE KEY-----
Binary file added tests/data/wasm/faucet.wasm
Binary file not shown.
57 changes: 57 additions & 0 deletions tests/rpc/integration/put_deploy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//go:build integration
// +build integration

package integration

import (
"context"
"encoding/hex"
"log"
"math/big"
"net/http"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/make-software/casper-go-sdk/casper"
"github.com/make-software/casper-go-sdk/rpc"
"github.com/make-software/casper-go-sdk/types"
"github.com/make-software/casper-go-sdk/types/clvalue"
)

func Test_PutDeploy(t *testing.T) {
facetKeys, err := casper.NewED25519PrivateKeyFromPEMFile("../../data/keys/docker-nctl-secret.pem")
require.NoError(t, err)
require.NoError(t, err)
header := types.DefaultHeader()
header.ChainName = "casper-net-1"
header.Account = facetKeys.PublicKey()
require.NoError(t, err)
header.Timestamp = types.Timestamp(time.Now())
payment := types.StandardPayment(big.NewInt(4000000000))

moduleBytes, err := os.ReadFile("../../data/wasm/faucet.wasm")
require.NoError(t, err)

args := &types.Args{}
args.AddArgument("target", clvalue.NewCLByteArray(facetKeys.PublicKey().AccountHash().Hash.Bytes())).AddArgument("amount", *clvalue.NewCLUInt512(big.NewInt(1000000000000)))
session := types.ExecutableDeployItem{
ModuleBytes: &types.ModuleBytes{
ModuleBytes: hex.EncodeToString(moduleBytes),
Args: args,
},
}

deploy, err := types.MakeDeploy(header, payment, session)
err = deploy.SignDeploy(facetKeys)
require.NoError(t, err)

rpcClient := rpc.NewClient(rpc.NewHttpHandler("http://127.0.0.1:11101/rpc", http.DefaultClient))
res, err := rpcClient.PutDeploy(context.Background(), *deploy)
log.Println(deploy.Hash.ToHex())
require.NoError(t, err)
assert.NotEmpty(t, res.DeployHash)
}
3 changes: 2 additions & 1 deletion types/contract_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type ContractPackage struct {
// of the allowed groups is present in the caller’s context before execution.
Groups []ContractGroup `json:"groups"`
// List of active versions of a contract.
Versions []ContractVersion `json:"versions"`
Versions []ContractVersion `json:"versions"`
LockStatus string `json:"lock_status"`
}

// ContractGroup associate a set of URefs with a label.
Expand Down

0 comments on commit 6a8b30e

Please sign in to comment.