-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from alex-semenyuk/deploy_tezos_contract
DeployContract implementation for Tezos connector
- Loading branch information
Showing
3 changed files
with
217 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,135 @@ | ||
package tezos | ||
|
||
import ( | ||
"context" | ||
"blockwatch.cc/tzgo/rpc" | ||
"blockwatch.cc/tzgo/tezos" | ||
"github.com/stretchr/testify/mock" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/fftypes" | ||
"github.com/hyperledger/firefly-transaction-manager/pkg/ffcapi" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDeployContractPrepare(t *testing.T) { | ||
_, c, _, done := newTestConnector(t) | ||
ctx, c, mRPC, done := newTestConnector(t) | ||
defer done() | ||
mRPC.On("GetBlockHash", ctx, mock.Anything, mock.Anything). | ||
Return(tezos.BlockHash{}, nil) | ||
mRPC.On("GetContractExt", ctx, mock.Anything, mock.Anything). | ||
Return(&rpc.ContractInfo{ | ||
Counter: 10, | ||
Manager: "edpkv89Jj4aVWetK69CWm5ss1LayvK8dQoiFz7p995y1k3E8CZwqJ6", | ||
}, nil) | ||
mRPC.On("Simulate", ctx, mock.Anything, mock.Anything). | ||
Return(&rpc.Receipt{ | ||
Op: &rpc.Operation{ | ||
Contents: []rpc.TypedOperation{ | ||
rpc.Transaction{ | ||
Manager: rpc.Manager{ | ||
Generic: rpc.Generic{ | ||
Metadata: rpc.OperationMetadata{ | ||
Result: rpc.OperationResult{ | ||
Status: tezos.OpStatusApplied, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, nil) | ||
|
||
_, _, err := c.DeployContractPrepare(context.Background(), &ffcapi.ContractDeployPrepareRequest{}) | ||
resp, reason, err := c.DeployContractPrepare(ctx, &ffcapi.ContractDeployPrepareRequest{ | ||
Contract: fftypes.JSONAnyPtr("{\"code\":[{\"args\":[{\"prim\":\"string\"}],\"prim\":\"parameter\"},{\"args\":[{\"prim\":\"string\"}],\"prim\":\"storage\"},{\"args\":[[{\"prim\":\"CAR\"},{\"args\":[{\"prim\":\"operation\"}],\"prim\":\"NIL\"},{\"prim\":\"PAIR\"}]],\"prim\":\"code\"}],\"storage\":{\"string\":\"hello\"}}"), | ||
}) | ||
|
||
assert.NotNil(t, resp) | ||
assert.Equal(t, reason, ffcapi.ErrorReason("")) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestDeployContractPrepareGetContractExtError(t *testing.T) { | ||
ctx, c, mRPC, done := newTestConnector(t) | ||
defer done() | ||
mRPC.On("GetBlockHash", ctx, mock.Anything, mock.Anything). | ||
Return(tezos.BlockHash{}, nil) | ||
mRPC.On("GetContractExt", ctx, mock.Anything, mock.Anything). | ||
Return(&rpc.ContractInfo{ | ||
Counter: 10, | ||
Manager: "edpkv89Jj4aVWetK69CWm5ss1LayvK8dQoiFz7p995y1k3E8CZwqJ6", | ||
}, assert.AnError) | ||
|
||
resp, reason, err := c.DeployContractPrepare(ctx, &ffcapi.ContractDeployPrepareRequest{ | ||
Contract: fftypes.JSONAnyPtr("{\"code\":[{\"args\":[{\"prim\":\"string\"}],\"prim\":\"parameter\"},{\"args\":[{\"prim\":\"string\"}],\"prim\":\"storage\"},{\"args\":[[{\"prim\":\"CAR\"},{\"args\":[{\"prim\":\"operation\"}],\"prim\":\"NIL\"},{\"prim\":\"PAIR\"}]],\"prim\":\"code\"}],\"storage\":{\"string\":\"hello\"}}"), | ||
}) | ||
|
||
assert.Nil(t, resp) | ||
assert.Error(t, err) | ||
assert.Equal(t, reason, ffcapi.ErrorReasonInvalidInputs) | ||
} | ||
|
||
func TestDeployContractPrepareSimulateError(t *testing.T) { | ||
ctx, c, mRPC, done := newTestConnector(t) | ||
defer done() | ||
mRPC.On("GetBlockHash", ctx, mock.Anything, mock.Anything). | ||
Return(tezos.BlockHash{}, nil) | ||
mRPC.On("GetContractExt", ctx, mock.Anything, mock.Anything). | ||
Return(&rpc.ContractInfo{ | ||
Counter: 10, | ||
Manager: "edpkv89Jj4aVWetK69CWm5ss1LayvK8dQoiFz7p995y1k3E8CZwqJ6", | ||
}, nil) | ||
mRPC.On("Simulate", ctx, mock.Anything, mock.Anything). | ||
Return(&rpc.Receipt{ | ||
Op: &rpc.Operation{ | ||
Contents: []rpc.TypedOperation{ | ||
rpc.Transaction{ | ||
Manager: rpc.Manager{ | ||
Generic: rpc.Generic{ | ||
Metadata: rpc.OperationMetadata{ | ||
Result: rpc.OperationResult{ | ||
Status: tezos.OpStatusApplied, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, assert.AnError) | ||
|
||
resp, reason, err := c.DeployContractPrepare(ctx, &ffcapi.ContractDeployPrepareRequest{ | ||
Contract: fftypes.JSONAnyPtr("{\"code\":[{\"args\":[{\"prim\":\"string\"}],\"prim\":\"parameter\"},{\"args\":[{\"prim\":\"string\"}],\"prim\":\"storage\"},{\"args\":[[{\"prim\":\"CAR\"},{\"args\":[{\"prim\":\"operation\"}],\"prim\":\"NIL\"},{\"prim\":\"PAIR\"}]],\"prim\":\"code\"}],\"storage\":{\"string\":\"hello\"}}"), | ||
}) | ||
|
||
assert.Nil(t, resp) | ||
assert.Error(t, err) | ||
assert.Equal(t, reason, ffcapi.ErrorReason("")) | ||
} | ||
|
||
func TestDeployContractPrepareMisingContractError(t *testing.T) { | ||
ctx, c, _, done := newTestConnector(t) | ||
defer done() | ||
|
||
resp, reason, err := c.DeployContractPrepare(ctx, &ffcapi.ContractDeployPrepareRequest{}) | ||
|
||
assert.Nil(t, resp) | ||
assert.Error(t, err) | ||
assert.Equal(t, reason, ffcapi.ErrorReasonInvalidInputs) | ||
} | ||
|
||
func TestDeployContractPrepareParseAddressError(t *testing.T) { | ||
ctx, c, _, done := newTestConnector(t) | ||
defer done() | ||
|
||
resp, reason, err := c.DeployContractPrepare(ctx, &ffcapi.ContractDeployPrepareRequest{ | ||
TransactionHeaders: ffcapi.TransactionHeaders{ | ||
From: "wrong", | ||
}, | ||
Contract: fftypes.JSONAnyPtr("{\"code\":[{\"args\":[{\"prim\":\"string\"}],\"prim\":\"parameter\"},{\"args\":[{\"prim\":\"string\"}],\"prim\":\"storage\"},{\"args\":[[{\"prim\":\"CAR\"},{\"args\":[{\"prim\":\"operation\"}],\"prim\":\"NIL\"},{\"prim\":\"PAIR\"}]],\"prim\":\"code\"}],\"storage\":{\"string\":\"hello\"}}"), | ||
}) | ||
|
||
assert.Nil(t, resp) | ||
assert.Error(t, err) | ||
assert.Equal(t, err.Error(), "contract deployment is not supported") | ||
assert.Equal(t, reason, ffcapi.ErrorReasonInvalidInputs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters