@@ -23,6 +23,7 @@ import (
2323 "testing"
2424
2525 "github.com/onflow/flow-go-sdk"
26+ flowsdk "github.com/onflow/flow-go-sdk"
2627 "github.com/stretchr/testify/assert"
2728 "github.com/stretchr/testify/mock"
2829
@@ -290,3 +291,79 @@ func TestDependencyInstallerAddMany(t *testing.T) {
290291 }
291292 })
292293}
294+
295+ func TestDependencyInstallerAliasTracking (t * testing.T ) {
296+ logger := output .NewStdoutLogger (output .NoneLog )
297+ _ , state , _ := util .TestMocks (t )
298+
299+ serviceAcc , _ := state .EmulatorServiceAccount ()
300+ serviceAddress := serviceAcc .Address
301+
302+ t .Run ("AutoApplyAliasForSameAccount" , func (t * testing.T ) {
303+ gw := mocks .DefaultMockGateway ()
304+
305+ // Mock the same account for both contracts
306+ gw .GetAccount .Run (func (args mock.Arguments ) {
307+ addr := args .Get (1 ).(flow.Address )
308+ assert .Equal (t , addr .String (), serviceAcc .Address .String ())
309+ acc := tests .NewAccountWithAddress (addr .String ())
310+ acc .Contracts = map [string ][]byte {
311+ "ContractOne" : []byte ("access(all) contract ContractOne {}" ),
312+ "ContractTwo" : []byte ("access(all) contract ContractTwo {}" ),
313+ }
314+
315+ gw .GetAccount .Return (acc , nil )
316+ })
317+
318+ di := & DependencyInstaller {
319+ Gateways : map [string ]gateway.Gateway {
320+ config .EmulatorNetwork .Name : gw .Mock ,
321+ config .TestnetNetwork .Name : gw .Mock ,
322+ config .MainnetNetwork .Name : gw .Mock ,
323+ },
324+ Logger : logger ,
325+ State : state ,
326+ SaveState : true ,
327+ TargetDir : "" ,
328+ SkipDeployments : true ,
329+ SkipAlias : false ,
330+ dependencies : make (map [string ]config.Dependency ),
331+ accountAliases : make (map [string ]map [string ]flowsdk.Address ),
332+ }
333+
334+ // Add first contract - this should prompt for alias
335+ dep1 := config.Dependency {
336+ Name : "ContractOne" ,
337+ Source : config.Source {
338+ NetworkName : "mainnet" ,
339+ Address : flow .HexToAddress (serviceAddress .String ()),
340+ ContractName : "ContractOne" ,
341+ },
342+ }
343+ di .dependencies ["mainnet://" + serviceAddress .String ()+ ".ContractOne" ] = dep1
344+
345+ // Simulate user providing an alias for the first contract
346+ aliasAddress := flowsdk .HexToAddress ("0x1234567890abcdef" )
347+ di .setAccountAlias (serviceAddress .String (), "testnet" , aliasAddress )
348+
349+ // Add second contract - this should automatically use the same alias
350+ dep2 := config.Dependency {
351+ Name : "ContractTwo" ,
352+ Source : config.Source {
353+ NetworkName : "mainnet" ,
354+ Address : flow .HexToAddress (serviceAddress .String ()),
355+ ContractName : "ContractTwo" ,
356+ },
357+ }
358+ di .dependencies ["mainnet://" + serviceAddress .String ()+ ".ContractTwo" ] = dep2
359+
360+ // Verify that the alias is automatically applied
361+ existingAlias , exists := di .getAccountAlias (serviceAddress .String (), "testnet" )
362+ assert .True (t , exists , "Alias should exist for the account" )
363+ assert .Equal (t , aliasAddress , existingAlias , "Alias should match the stored value" )
364+
365+ // Test that getCurrentContractAccountAddress works correctly
366+ accountAddr := di .getCurrentContractAccountAddress ("ContractOne" , "mainnet" )
367+ assert .Equal (t , serviceAddress .String (), accountAddr , "Should return correct account address" )
368+ })
369+ }
0 commit comments