Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
camilbancioiu committed Nov 6, 2023
1 parent 8149d9c commit 62c88eb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
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
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.
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

0 comments on commit 62c88eb

Please sign in to comment.