Skip to content

Commit

Permalink
assert old program is not get or set during program
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Jun 3, 2022
1 parent 6405659 commit 88b4d7e
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions runtime/contract_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func TestContractUpdateWithDependencies(t *testing.T) {
runtime := newTestInterpreterRuntime()
accountCodes := map[common.LocationID][]byte{}
signerAccount := common.MustBytesToAddress([]byte{0x1})
fooLocation := common.AddressLocation{
Address: signerAccount,
Name: "Foo",
}

var checkGetSetProgram, getProgramCalled, setProgramCalled bool

runtimeInterface := &testRuntimeInterface{
getCode: func(location Location) (bytes []byte, err error) {
Expand Down Expand Up @@ -68,11 +74,25 @@ func TestContractUpdateWithDependencies(t *testing.T) {
decodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
return json.Decode(nil, b)
},

// Always force to get the old program from the source during the update.
getProgram: func(location Location) (*interpreter.Program, error) {
_, isTransactionLocation := location.(common.TransactionLocation)
if checkGetSetProgram && !isTransactionLocation {
require.Equal(t, location, fooLocation)
require.False(t, getProgramCalled)
getProgramCalled = true
}
// Always force to get the old program from the source during the update.
return nil, nil
},
setProgram: func(location Location, program *interpreter.Program) error {
_, isTransactionLocation := location.(common.TransactionLocation)
if checkGetSetProgram && !isTransactionLocation {
require.Equal(t, location, fooLocation)
require.False(t, setProgramCalled)
setProgramCalled = true
}
return nil
},
}

runtime.SetContractUpdateValidationEnabled(true)
Expand Down Expand Up @@ -176,6 +196,8 @@ func TestContractUpdateWithDependencies(t *testing.T) {

signerAccount = common.MustBytesToAddress([]byte{0x2})

checkGetSetProgram = true

err = runtime.ExecuteTransaction(
Script{
Source: []byte(fmt.Sprintf(
Expand Down

0 comments on commit 88b4d7e

Please sign in to comment.