Skip to content

Commit

Permalink
Merge pull request #1247 from onflow/bjartek/add-deployment-block-whe…
Browse files Browse the repository at this point in the history
…n-adding-contract

Adding a contract to deployment section when using flowkit.AddContract
  • Loading branch information
chasefleming authored Oct 26, 2023
2 parents c615d33 + bf00858 commit fef7105
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
19 changes: 13 additions & 6 deletions flowkit/flowkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ func (f *Flowkit) prepareTransaction(
tx *transactions.Transaction,
account *accounts.Account,
) (*transactions.Transaction, error) {

block, err := f.gateway.GetLatestBlock()
if err != nil {
return nil, err
Expand Down Expand Up @@ -360,10 +359,19 @@ func (f *Flowkit) AddContract(
}

d := state.Deployments().ByAccountAndNetwork(account.Name, f.network.Name)
cd := config.ContractDeployment{
Name: name,
Args: contract.Args,
}
if d != nil {
d.AddContract(config.ContractDeployment{
Name: name,
})
d.AddContract(cd)
} else {
deployment := config.Deployment{
Network: f.network.Name,
Account: account.Name,
Contracts: []config.ContractDeployment{cd},
}
state.Deployments().AddOrUpdate(deployment)
}

// don't add contract if it already exists because it might overwrite existing data
Expand Down Expand Up @@ -549,7 +557,7 @@ func makeEventQueries(
) []grpc.EventRangeQuery {
var queries []grpc.EventRangeQuery
for startHeight <= endHeight {
suggestedEndHeight := startHeight + blockCount - 1 //since we are inclusive
suggestedEndHeight := startHeight + blockCount - 1 // since we are inclusive
end := endHeight
if suggestedEndHeight < endHeight {
end = suggestedEndHeight
Expand All @@ -564,7 +572,6 @@ func makeEventQueries(
startHeight = suggestedEndHeight + 1
}
return queries

}

// GenerateKey using the signature algorithm and optional seed. If seed is not provided a random safe seed will be generated.
Expand Down
28 changes: 10 additions & 18 deletions flowkit/flowkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ func TestAccountsCreate_Integration(t *testing.T) {
}

}

})

t.Run("Create Invalid", func(t *testing.T) {
Expand Down Expand Up @@ -428,7 +427,6 @@ func TestAccountsCreate_Integration(t *testing.T) {
assert.Equal(t, errMsg, err.Error())
}
})

}

func TestAccountsAddContract_Integration(t *testing.T) {
Expand Down Expand Up @@ -463,6 +461,13 @@ func TestAccountsAddContract_Integration(t *testing.T) {
acc, err = flowkit.GetAccount(ctx, srvAcc.Address)
require.NoError(t, err)
assert.Equal(t, acc.Contracts["Simple"], tests.ContractSimpleUpdated.Source)

contract, err := state.Contracts().ByName(tests.ContractSimpleUpdated.Name)
require.NoError(t, err)
require.NotNil(t, contract)

deployments := state.Deployments().ByAccountAndNetwork(srvAcc.Name, "emulator")
require.NotNil(t, deployments)
})

t.Run("Add Contract Invalid Same Content", func(t *testing.T) {
Expand Down Expand Up @@ -574,7 +579,7 @@ func TestAccountsAddContractWithArgs(t *testing.T) {
state, flowkit := setupIntegration()
srvAcc, _ := state.EmulatorServiceAccount()

//adding contract without argument should return an error
// adding contract without argument should return an error
_, _, err := flowkit.AddContract(
ctx,
srvAcc,
Expand Down Expand Up @@ -693,7 +698,6 @@ func TestBlocks(t *testing.T) {
gw.Mock.AssertNotCalled(t, mocks.GetBlockByHeightFunc)
gw.Mock.AssertNotCalled(t, mocks.GetLatestBlockFunc)
})

}

func TestBlocksGet_Integration(t *testing.T) {
Expand Down Expand Up @@ -741,7 +745,6 @@ func TestEvents(t *testing.T) {
})

t.Run("Test create queries", func(t *testing.T) {

names := []string{"first", "second"}
queries := makeEventQueries(names, 0, 400, 250)
expected := []grpc.EventRangeQuery{
Expand All @@ -764,7 +767,6 @@ func TestEvents(t *testing.T) {

assert.EqualError(t, err, "failed getting event")
})

}

func TestEvents_Integration(t *testing.T) {
Expand Down Expand Up @@ -913,12 +915,12 @@ func TestKeys(t *testing.T) {
assert.Equal(t, key.String(), "0x638dc9ad0eee91d09249f0fd7c5323a11600e20d5b9105b66b782a96236e74cf")
})

//https://github.com/onflow/ledger-app-flow/blob/dc61213a9c3d73152b78b7391d04165d07f1ad89/tests_speculos/test-basic-show-address-expert.js#L28
// https://github.com/onflow/ledger-app-flow/blob/dc61213a9c3d73152b78b7391d04165d07f1ad89/tests_speculos/test-basic-show-address-expert.js#L28
t.Run("Generate Keys with mnemonic (custom path - Ledger)", func(t *testing.T) {
t.Parallel()

_, flowkit, _ := setup()
//ledger test mnemonic: https://github.com/onflow/ledger-app-flow#using-a-real-device-for-integration-tests-nano-s-and-nano-s-plus
// ledger test mnemonic: https://github.com/onflow/ledger-app-flow#using-a-real-device-for-integration-tests-nano-s-and-nano-s-plus
key, err := flowkit.DerivePrivateKeyFromMnemonic(ctx, "equip will roof matter pink blind book anxiety banner elbow sun young", crypto.ECDSA_secp256k1, "m/44'/539'/513'/0/0")

assert.NoError(t, err)
Expand Down Expand Up @@ -957,7 +959,6 @@ func TestKeys(t *testing.T) {
x++
}
}

})
}

Expand Down Expand Up @@ -1198,7 +1199,6 @@ func TestProject(t *testing.T) {
assert.Equal(t, len(contracts), 1)
assert.Equal(t, contracts[0].AccountAddress, acct2.Address)
})

}

// used for integration tests
Expand Down Expand Up @@ -1325,7 +1325,6 @@ func TestProject_Integration(t *testing.T) {
_, err = simpleDeploy(state, flowkit, true)
assert.NoError(t, err)
})

}

func TestScripts(t *testing.T) {
Expand All @@ -1350,7 +1349,6 @@ func TestScripts(t *testing.T) {

assert.NoError(t, err)
})

}

func TestScripts_Integration(t *testing.T) {
Expand Down Expand Up @@ -1388,7 +1386,6 @@ func TestScripts_Integration(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "cannot find type in this scope")
assert.Nil(t, res)

})

t.Run("Execute With Imports", func(t *testing.T) {
Expand Down Expand Up @@ -1454,7 +1451,6 @@ func TestScripts_Integration(t *testing.T) {
assert.NotNil(t, err)
assert.Equal(t, err.Error(), out[x])
}

})
}

Expand Down Expand Up @@ -1514,7 +1510,6 @@ func TestTransactions(t *testing.T) {
gw.Mock.AssertNumberOfCalls(t, mocks.SendSignedTransactionFunc, 1)
gw.Mock.AssertNumberOfCalls(t, mocks.GetTransactionResultFunc, 1)
})

}

func setupAccounts(state *State, flowkit Flowkit) {
Expand Down Expand Up @@ -1712,7 +1707,6 @@ func TestTransactions_Integration(t *testing.T) {
assert.Equal(t, ftx.ProposalKey.Address, txIn.prop)
assert.Equal(t, ftx.ProposalKey.KeyIndex, txIn.index)
}

})

t.Run("Build Transaction with Imports", func(t *testing.T) {
Expand Down Expand Up @@ -1850,7 +1844,6 @@ func TestTransactions_Integration(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, txResult.Status, flow.TransactionStatusSealed)
assert.NotNil(t, txSent.ID())

})

t.Run("Fails signing transaction, wrong account", func(t *testing.T) {
Expand Down Expand Up @@ -2090,5 +2083,4 @@ func Test_BlockQuery(t *testing.T) {

_, err = NewBlockQuery("invalid")
assert.EqualError(t, err, "invalid query: invalid, valid are: \"latest\", block height or block ID")

}

0 comments on commit fef7105

Please sign in to comment.