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

upgrade from contract fix #793

Merged
merged 8 commits into from
Nov 7, 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
22 changes: 11 additions & 11 deletions integrationTests/json/scenariosAdderLog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
)

const expectedAdderLog = `starting log:
GetFunctionNames: [add callBack getSum init]
GetFunctionNames: [add callBack getSum init upgrade]
ValidateFunctionArities: true
GetFunctionNames: [add callBack getSum init]
GetFunctionNames: [add callBack getSum init]
GetFunctionNames: [add callBack getSum init upgrade]
GetFunctionNames: [add callBack getSum init upgrade]
HasFunction(init): true
CallFunction(init):
VM hook begin: CheckNoPayment()
Expand All @@ -23,12 +23,12 @@ VM hook begin: BigIntGetUnsignedArgument(0, -101)
GetPointsUsed: 249
SetPointsUsed: 1249
VM hook end: BigIntGetUnsignedArgument(0, -101)
VM hook begin: MBufferSetBytes(-102, 1048601, 3)
VM hook begin: MBufferSetBytes(-102, 131097, 3)
GetPointsUsed: 1289
SetPointsUsed: 3289
GetPointsUsed: 3289
SetPointsUsed: 6289
VM hook end: MBufferSetBytes(-102, 1048601, 3)
VM hook end: MBufferSetBytes(-102, 131097, 3)
VM hook begin: MBufferFromBigIntUnsigned(-103, -101)
GetPointsUsed: 6333
SetPointsUsed: 10333
Expand All @@ -52,7 +52,7 @@ GetPointsUsed: 135352
GetPointsUsed: 135352
Reset: true
SetPointsUsed: 0
SetGasLimit: 9223372036853567307
SetGasLimit: 9223372036853566707
SetBreakpointValue: 0
HasFunction(getSum): true
CallFunction(getSum):
Expand All @@ -64,12 +64,12 @@ VM hook begin: GetNumArguments()
GetPointsUsed: 110
SetPointsUsed: 210
VM hook end: GetNumArguments()
VM hook begin: MBufferSetBytes(-101, 1048601, 3)
VM hook begin: MBufferSetBytes(-101, 131097, 3)
GetPointsUsed: 250
SetPointsUsed: 2250
GetPointsUsed: 2250
SetPointsUsed: 5250
VM hook end: MBufferSetBytes(-101, 1048601, 3)
VM hook end: MBufferSetBytes(-101, 131097, 3)
VM hook begin: MBufferStorageLoad(-101, -102)
GetPointsUsed: 5291
SetPointsUsed: 6291
Expand Down Expand Up @@ -97,7 +97,7 @@ GetPointsUsed: 71337
GetPointsUsed: 71337
Reset: true
SetPointsUsed: 0
SetGasLimit: 3791500
SetGasLimit: 3790900
SetBreakpointValue: 0
HasFunction(add): true
CallFunction(add):
Expand All @@ -113,12 +113,12 @@ VM hook begin: BigIntGetUnsignedArgument(0, -101)
GetPointsUsed: 249
SetPointsUsed: 1249
VM hook end: BigIntGetUnsignedArgument(0, -101)
VM hook begin: MBufferSetBytes(-102, 1048601, 3)
VM hook begin: MBufferSetBytes(-102, 131097, 3)
GetPointsUsed: 1289
SetPointsUsed: 3289
GetPointsUsed: 3289
SetPointsUsed: 6289
VM hook end: MBufferSetBytes(-102, 1048601, 3)
VM hook end: MBufferSetBytes(-102, 131097, 3)
VM hook begin: MBufferStorageLoad(-102, -103)
GetPointsUsed: 6333
SetPointsUsed: 7333
Expand Down
8 changes: 0 additions & 8 deletions integrationTests/json/scenariosFeatures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ func TestRustPromisesFeatures(t *testing.T) {
CheckNoError()
}

// TODO: debug, then delete
func TestRustPromisesFeaturesDebug(t *testing.T) {
ScenariosTest(t).
Folder("features/composability/scenarios-promises/promises_call_async_retrieve_egld.scen.json").
Run().
CheckNoError()
}

func TestRustFormattedMessageFeatures(t *testing.T) {
ScenariosTest(t).
Folder("features/formatted-message-features/scenarios").
Expand Down
6 changes: 6 additions & 0 deletions mock/contracts/deployerSimpleSC.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func InitMockMethod(instanceMock *mock.InstanceMock, config interface{}) {
instanceMock.AddMockMethod("init", testcommon.SimpleWasteGasMockMethod(instanceMock, testConfig.GasUsedByInit))
}

// UpgradeMockMethod -
func UpgradeMockMethod(instanceMock *mock.InstanceMock, config interface{}) {
testConfig := config.(*testcommon.TestConfig)
instanceMock.AddMockMethod("upgrade", testcommon.SimpleWasteGasMockMethod(instanceMock, testConfig.GasUsedByInit))
}

// CallbackTestConfig -
type CallbackTestConfig interface {
CallbackFails() bool
Expand Down
Binary file modified test/adder/output/adder.wasm
Binary file not shown.
4 changes: 4 additions & 0 deletions test/contracts/init-correct/init-correct.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ void init() {
}
}
}

void upgrade() {
init();
}
1 change: 1 addition & 0 deletions test/contracts/init-correct/init-correct.export
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
init
upgrade
Binary file modified test/contracts/init-correct/output/init-correct.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"sc:forwarder": {
"code": "file:../forwarder-raw/output/forwarder-raw.wasm"
},
"sc:reference": {
"code": "file:../vault/output/vault-upgrade.wasm"
},
"sc:child": {
"code": "file:../vault/output/vault.wasm",
"owner": "sc:forwarder"
Expand All @@ -16,27 +19,28 @@
},
{
"step": "scCall",
"id": "upgrade-vault-to-forwarder",
"id": "upgrade-vault-from-source",
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"function": "call_upgrade_from_source",
"arguments": [
"sc:child",
"sc:forwarder"
"sc:reference"
],
"gasLimit": "500,000,000",
"gasPrice": "0"
},
"expect": {
"out": []
"out": "*",
"status": ""
}
},
{
"step": "checkState",
"accounts": {
"sc:child": {
"code": "file:../forwarder-raw/output/forwarder-raw.wasm"
"code": "file:../vault/output/vault-upgrade.wasm"
},
"+": ""
}
Expand All @@ -58,6 +62,7 @@
},
"expect": {
"out": [
"str:upgraded",
"str:upgrade-init-arg"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"code": "file:../forwarder-raw/output/forwarder-raw.wasm",
"owner": "sc:forwarder"
},
"sc:vault": {
"code": "file:../vault/output/vault.wasm"
"sc:reference": {
"code": "file:../vault/output/vault-upgrade.wasm"
}
}
},
Expand All @@ -23,13 +23,15 @@
"function": "call_upgrade_from_source",
"arguments": [
"sc:forwarder",
"sc:vault"
"sc:reference"
],
"gasLimit": "500,000,000",
"gasPrice": "0"
},
"expect": {
"out": []
"out": [
"str:upgraded"
]
}
},
{
Expand All @@ -39,11 +41,11 @@
"nonce": "*"
},
"sc:forwarder": {
"code": "file:../vault/output/vault.wasm",
"code": "file:../vault/output/vault-upgrade.wasm",
"owner": "sc:forwarder"
},
"sc:vault": {
"code": "file:../vault/output/vault.wasm"
"sc:reference": {
"code": "file:../vault/output/vault-upgrade.wasm"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"sc:forwarder": {
"code": "file:../forwarder/output/forwarder.wasm"
},
"sc:reference": {
"code": "file:../vault/output/vault-upgrade.wasm"
},
"sc:child": {
"code": "file:../vault/output/vault.wasm",
"owner": "sc:forwarder"
Expand All @@ -16,27 +19,28 @@
},
{
"step": "scCall",
"id": "upgrade-vault-to-forwarder",
"id": "upgrade-vault-from-source",
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"function": "upgrade_vault_from_source",
"arguments": [
"sc:child",
"sc:forwarder"
"sc:reference"
],
"gasLimit": "500,000,000",
"gasPrice": "0"
},
"expect": {
"out": []
"out": "*",
"status": ""
}
},
{
"step": "checkState",
"accounts": {
"sc:child": {
"code": "file:../forwarder/output/forwarder.wasm"
"code": "file:../vault/output/vault-upgrade.wasm"
},
"+": ""
}
Expand All @@ -51,13 +55,56 @@
"function": "upgradeVault",
"arguments": [
"sc:child",
"file:../vault/output/vault.wasm"
"file:../vault/output/vault.wasm",
"str:arg"
],
"gasLimit": "500,000,000",
"gasPrice": "0"
},
"expect": {
"out": []
"out": "*",
"logs": [
{
"address": "sc:forwarder",
"endpoint": "str:transferValueOnly",
"topics": [
"",
"sc:child"
],
"data": [
"str:UpgradeFromSource",
"str:upgradeContract",
"*",
"0x0100",
"str:arg"
]
},
{
"address": "sc:child",
"endpoint": "str:upgradeContract",
"topics": [
"str:upgraded"
],
"data": [
""
]
},
{
"address": "sc:child",
"endpoint": "str:transferValueOnly",
"topics": [
"",
"sc:forwarder"
],
"data": [
"str:AsyncCallback",
"str:callBack",
"0x00",
"str:upgraded",
"str:arg"
]
}
]
}
},
{
Expand Down
Binary file modified test/features/composability/vault/output/vault-promises.wasm
Binary file not shown.
Binary file not shown.
Binary file modified test/features/composability/vault/output/vault.wasm
Binary file not shown.
Binary file modified test/multisig/output/multisig-full.wasm
Binary file not shown.
Binary file modified test/multisig/output/multisig-view.wasm
Binary file not shown.
Binary file modified test/multisig/output/multisig.wasm
Binary file not shown.
Binary file modified test/multisig/test-contracts/adder.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion vmhost/hostCore/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ func (host *vmHost) executeUpgrade(input *vmcommon.ContractCallInput) error {
return vmhost.ErrContractInvalid
}

err = host.callInitFunction()
err = host.callUpgradeFunction()
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion vmhost/hosttest/contracts_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,14 @@ func runUpdateFromSourceTest(t *testing.T, testConfig *testcommon.TestConfig, as
var deployedContract test.MockTestSmartContract
var contractToUpdate test.MockTestSmartContract
if testConfig.DeployedContractAddress != nil {
// The DeployedContract will be the source of the code to be written in
// ContractToBeUpdated. Therefore it is the DeployedContract which must
// initially have UpgradeMockMethod. After the code update, the
// ContractToBeUpdated will also have the UpgradeMockMethod and it will be
// called by the VM.
deployedContract = test.CreateMockContract(testConfig.DeployedContractAddress).
WithConfig(testConfig).
WithMethods(contracts.InitMockMethod)
WithMethods(contracts.InitMockMethod, contracts.UpgradeMockMethod)
}
if testConfig.ContractToBeUpdatedAddress != nil {
contractToUpdate = test.CreateMockContract(testConfig.ContractToBeUpdatedAddress).
Expand Down
10 changes: 5 additions & 5 deletions vmhost/hosttest/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestExecution_DeployWASM_Successful(t *testing.T) {
AndAssertResults(func(blockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) {
verify.Ok().
ReturnData([]byte("init successful")).
GasRemaining(430).
GasRemaining(410).
Nonce([]byte("caller"), 24).
Code(newAddress, input.ContractCode).
BalanceDelta(newAddress, 88)
Expand Down Expand Up @@ -449,7 +449,7 @@ func TestExecution_Deploy_DisallowFloatingPoint(t *testing.T) {

func TestExecution_DeployWASM_GasValidation(t *testing.T) {
var gasProvided uint64
gasUsedByDeployment := uint64(570)
gasUsedByDeployment := uint64(590)

inputBuilder := test.CreateTestContractCreateInputBuilder().
WithContractCode(test.GetTestSCCode("init-correct", "../../")).
Expand Down Expand Up @@ -2983,13 +2983,13 @@ func TestExecution_CreateNewContract_Success(t *testing.T) {
AndAssertResults(func(host vmhost.VMHost, stubBlockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) {
verify.Ok().
Balance(test.ParentAddress, 1000).
GasUsed(test.ParentAddress, 1069).
GasRemaining(998361).
GasUsed(test.ParentAddress, 1109).
GasRemaining(998301).
BalanceDelta(childAddress, 42).
Code(childAddress, childCode).
CodeMetadata(childAddress, []byte{1, 0}).
CodeDeployerAddress(childAddress, test.ParentAddress).
GasUsed(childAddress, 570).
GasUsed(childAddress, 590).
ReturnData([]byte{byte(l / 256), byte(l % 256)}, []byte("init successful"), []byte("succ")).
Storage().
Logs(vmcommon.LogEntry{
Expand Down
Loading