add test for alias name import
@@ -192,7 +192,81 @@ func TestProject(t *testing.T) {
})
t.Run("Deploy Project New Import Schema and Aliases", func(t *testing.T) {
- // todo
+ t.Parallel()
+
+ emulator := config.DefaultEmulatorNetwork().Name
+ state, s, gw := setup()
+
+ c1 := config.Contract{
+ Name: "ContractBB",
+ Location: tests.ContractBB.Filename,
+ Network: emulator,
+ }
+ state.Contracts().AddOrUpdate(c1.Name, c1)
+
+ c2 := config.Contract{
+ Name: "ContractAA",
+ Location: tests.ContractAA.Filename,
+ Network: emulator,
+ Alias: tests.Donald().Address().String(),
+ }
+ state.Contracts().AddOrUpdate(c2.Name, c2)
+
+ c3 := config.Contract{
+ Name: "ContractCC",
+ Location: tests.ContractCC.Filename,
+ Network: emulator,
+ }
+ state.Contracts().AddOrUpdate(c3.Name, c3)
+
+ state.Networks().AddOrUpdate(emulator, config.DefaultEmulatorNetwork())
+
+ a := tests.Alice()
+ state.Accounts().AddOrUpdate(a)
+
+ d := config.Deployment{
+ Network: emulator,
+ Account: a.Name(),
+ Contracts: []config.ContractDeployment{
+ {Name: c1.Name}, {Name: c3.Name},
+ },
+ }
+ state.Deployments().AddOrUpdate(d)
+
+ // for checking imports are correctly resolved
+ resolved := map[string]string{
+ tests.ContractB.Name: fmt.Sprintf(`import ContractAA from 0x%s`, tests.Donald().Address().Hex()),
+ tests.ContractC.Name: fmt.Sprintf(`
+ import ContractBB from 0x%s
+ import ContractAA from 0x%s`, a.Address().Hex(), tests.Donald().Address().Hex()),
+ } // don't change formatting of the above code since it compares the strings with included formatting
+
+ gw.SendSignedTransaction.Run(func(args mock.Arguments) {
+ tx := args.Get(0).(*flowkit.Transaction)
+ assert.Equal(t, tx.FlowTransaction().Payer, a.Address())
+ assert.True(t, strings.Contains(string(tx.FlowTransaction().Script), "signer.contracts.add"))
+
+ argCode := tx.FlowTransaction().Arguments[1]
+ decodeCode, _ := jsoncdc.Decode(nil, argCode)
+ code, _ := hex.DecodeString(decodeCode.ToGoValue().(string))
+
+ argName := tx.FlowTransaction().Arguments[0]
+ decodeName, _ := jsoncdc.Decode(nil, argName)
+
+ testCode, found := resolved[decodeName.ToGoValue().(string)]
+ require.True(t, found)
+ assert.True(t, strings.Contains(string(code), testCode))
+
+ gw.SendSignedTransaction.Return(tests.NewTransaction(), nil)
+ })
+
+ contracts, err := s.Project.Deploy(emulator, false)
+
+ assert.NoError(t, err)
+ assert.Equal(t, len(contracts), 2)
+ gw.Mock.AssertCalled(t, tests.GetLatestBlockFunc)
+ gw.Mock.AssertCalled(t, tests.GetAccountFunc, a.Address())
+ gw.Mock.AssertNumberOfCalls(t, tests.GetTransactionResultFunc, 2)
})
t.Run("Deploy Project Duplicate Address", func(t *testing.T) {
