-
Notifications
You must be signed in to change notification settings - Fork 12
/
deploy_native_test.go
90 lines (67 loc) · 3.11 KB
/
deploy_native_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2019 the orbs-network-go authors
// This file is part of the orbs-network-go library in the Orbs project.
//
// This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
// The above notice should be included in all copies or substantial portions of the software.
package e2e
import (
"fmt"
"testing"
"time"
"github.com/orbs-network/orbs-client-sdk-go/codec"
"github.com/orbs-network/orbs-network-go/test"
"github.com/orbs-network/orbs-network-go/test/contracts"
"github.com/stretchr/testify/require"
)
func TestDeploymentOfNativeContract(t *testing.T) {
if testing.Short() {
t.Skip("Skipping E2E tests in short mode")
}
runMultipleTimes(t, func(t *testing.T) {
h := NewAppHarness()
lt := time.Now()
PrintTestTime(t, "started", <)
h.WaitUntilTransactionPoolIsReady(t)
PrintTestTime(t, "first block committed", <)
counterStart := uint64(time.Now().UnixNano())
contractName := fmt.Sprintf("CounterFrom%d", counterStart)
fmt.Println("Will attempt to deploy contract with name: ", contractName)
PrintTestTime(t, "send deploy - start", <)
h.DeployContractAndRequireSuccess(t, OwnerOfAllSupply, contractName,
contracts.NativeSourceCodeForCounterPart1(counterStart),
contracts.NativeSourceCodeForCounterPart2(counterStart))
PrintTestTime(t, "send deploy - end", <)
// check counter
ok := test.Eventually(test.EVENTUALLY_DOCKER_E2E_TIMEOUT, func() bool {
PrintTestTime(t, "run query - start", <)
response, err2 := h.RunQuery(OwnerOfAllSupply.PublicKey(), contractName, "get")
PrintTestTime(t, "run query - end", <)
if err2 == nil && response.ExecutionResult == codec.EXECUTION_RESULT_SUCCESS {
return response.OutputArguments[0] == counterStart
}
return false
})
require.True(t, ok, "get counter should return counter start")
// transaction to add to the counter
amount := uint64(17)
PrintTestTime(t, "send transaction - start", <)
response, _, err := h.SendTransaction(OwnerOfAllSupply.PublicKey(), OwnerOfAllSupply.PrivateKey(), contractName, "add", uint64(amount))
PrintTestTime(t, "send transaction - end", <)
require.NoError(t, err, "add transaction should not return error")
requireSuccessful(t, response)
// check counter
ok = test.Eventually(test.EVENTUALLY_DOCKER_E2E_TIMEOUT, func() bool {
response, err := h.RunQuery(OwnerOfAllSupply.PublicKey(), contractName, "get")
if err == nil && response.ExecutionResult == codec.EXECUTION_RESULT_SUCCESS {
return response.OutputArguments[0] == counterStart+amount
}
return false
})
require.True(t, ok, "get counter should return counter start plus added value")
PrintTestTime(t, "attempting to deploy again to assert we can't deploy the same contract twice", <)
response, err = h.DeployNativeContract(OwnerOfAllSupply, contractName, []byte("some other code"))
require.NoError(t, err, "deployment transaction should fail but not return an error")
require.EqualValues(t, codec.EXECUTION_RESULT_ERROR_SMART_CONTRACT, response.ExecutionResult, "expected deploy contract to fail")
PrintTestTime(t, "done", <)
})
}