Skip to content

Commit 613d7d5

Browse files
committed
improve tests
1 parent a2af821 commit 613d7d5

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

internal/dependencymanager/dependencyinstaller_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,67 @@ func TestBlockHeightPinning(t *testing.T) {
23132313
assert.Equal(t, computeHash(newContractCode), updatedDep.Hash, "Should update to new version")
23142314
})
23152315

2316+
t.Run("SkipUpdatePromptsDoesNotErrorWhenOnChainDiffersFromFlowJson", func(t *testing.T) {
2317+
_, state, _ := util.TestMocks(t)
2318+
2319+
// What's in flow.json (old hash)
2320+
oldHash := "abc123old"
2321+
2322+
// What's on-chain at pinned block (hypothetically changed - shouldn't happen but testing edge case)
2323+
onChainCode := []byte("access(all) contract ChangedContract {}")
2324+
2325+
pinnedDep := config.Dependency{
2326+
Name: "ChangedContract",
2327+
BlockHeight: 10000,
2328+
Hash: oldHash, // flow.json has old hash
2329+
Source: config.Source{
2330+
NetworkName: config.EmulatorNetwork.Name,
2331+
Address: serviceAddress,
2332+
ContractName: "ChangedContract",
2333+
},
2334+
}
2335+
state.Dependencies().AddOrUpdate(pinnedDep)
2336+
2337+
gw := mocks.DefaultMockGateway()
2338+
gw.GetLatestBlock.Return(&flow.Block{
2339+
BlockHeader: flow.BlockHeader{Height: 50000},
2340+
}, nil)
2341+
2342+
// On-chain returns different contract (hash mismatch)
2343+
gw.GetAccountAtBlockHeight.Run(func(args mock.Arguments) {
2344+
acc := tests.NewAccountWithAddress(serviceAddress.String())
2345+
acc.Contracts = map[string][]byte{
2346+
"ChangedContract": onChainCode, // Different from flow.json hash!
2347+
}
2348+
gw.GetAccountAtBlockHeight.Return(acc, nil)
2349+
})
2350+
2351+
di := &DependencyInstaller{
2352+
Gateways: map[string]gateway.Gateway{
2353+
config.EmulatorNetwork.Name: gw.Mock,
2354+
},
2355+
Logger: logger,
2356+
State: state,
2357+
SaveState: false,
2358+
TargetDir: "",
2359+
SkipDeployments: true,
2360+
SkipAlias: true,
2361+
SkipUpdatePrompts: true, // --skip-update-prompts
2362+
dependencies: make(map[string]config.Dependency),
2363+
logs: categorizedLogs{},
2364+
prompter: &mockPrompter{responses: []bool{}},
2365+
}
2366+
2367+
// Key test: Should NOT error even though on-chain hash differs
2368+
// With no file, it installs the on-chain version
2369+
err := di.Add(pinnedDep)
2370+
assert.NoError(t, err, "Should not error when on-chain differs from flow.json with --skip-update-prompts")
2371+
2372+
// Should install the on-chain version (new hash)
2373+
savedDep := state.Dependencies().ByName("ChangedContract")
2374+
assert.Equal(t, computeHash(onChainCode), savedDep.Hash, "Should install on-chain version when no local file")
2375+
})
2376+
23162377
t.Run("BlockHeightFetchFailureReturnsError", func(t *testing.T) {
23172378
_, state, _ := util.TestMocks(t)
23182379

0 commit comments

Comments
 (0)