Skip to content

Commit

Permalink
Merge pull request #1818 from onflow/cf/fix-init-tx
Browse files Browse the repository at this point in the history
Simplify and fix the `init` Counter transaction
  • Loading branch information
chasefleming authored Nov 5, 2024
2 parents 921e9bd + c6a2839 commit 3e0a1f6
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 11 deletions.
22 changes: 21 additions & 1 deletion internal/super/generator/fixtures/README_no_deps.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 👋 Welcome Flow Developer!

Welcome to your new Flow project. This project is a starting point for you to develop smart contracts on the Flow Blockchain. It comes with example contracts, scripts, transactions, and tests to help you get started.
This project is a starting point for you to develop smart contracts on the Flow Blockchain. It comes with example contracts, scripts, transactions, and tests to help you get started.

## 🔨 Getting Started

Expand Down Expand Up @@ -29,6 +29,26 @@ Inside the `cadence` folder you will find:
- `/tests` - This folder contains your Cadence tests (integration tests for your contracts, scripts, and transactions to verify they behave as expected)
- `ExampleTest.cdc`

## Running the Existing Project

### Executing the `GetCounter` Script

To run the `GetCounter` script, use the following command:

```shell
flow scripts execute cadence/scripts/GetCounter.cdc
```

### Sending the `IncrementCounter` Transaction

To run the `IncrementCounter` transaction, use the following command:

```shell
flow transactions send cadence/transactions/IncrementCounter.cdc
```

To learn more about using the CLI, check out the [Flow CLI Documentation](https://developers.flow.com/tools/flow-cli).

## 👨‍💻 Start Developing

### Creating a New Contract
Expand Down
22 changes: 21 additions & 1 deletion internal/super/generator/fixtures/README_with_deps.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 👋 Welcome Flow Developer!

Welcome to your new Flow project. This project is a starting point for you to develop smart contracts on the Flow Blockchain. It comes with example contracts, scripts, transactions, and tests to help you get started.
This project is a starting point for you to develop smart contracts on the Flow Blockchain. It comes with example contracts, scripts, transactions, and tests to help you get started.

## 🔨 Getting Started

Expand Down Expand Up @@ -34,6 +34,26 @@ Inside the `cadence` folder you will find:
- `/tests` - This folder contains your Cadence tests (integration tests for your contracts, scripts, and transactions to verify they behave as expected)
- `ExampleTest.cdc`

## Running the Existing Project

### Executing the `GetCounter` Script

To run the `GetCounter` script, use the following command:

```shell
flow scripts execute cadence/scripts/GetCounter.cdc
```

### Sending the `IncrementCounter` Transaction

To run the `IncrementCounter` transaction, use the following command:

```shell
flow transactions send cadence/transactions/IncrementCounter.cdc
```

To learn more about using the CLI, check out the [Flow CLI Documentation](https://developers.flow.com/tools/flow-cli).

## 👨‍💻 Start Developing

### Creating a New Contract
Expand Down
22 changes: 21 additions & 1 deletion internal/super/generator/templates/README.md.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 👋 Welcome Flow Developer!

Welcome to your new Flow project. This project is a starting point for you to develop smart contracts on the Flow Blockchain. It comes with example contracts, scripts, transactions, and tests to help you get started.
This project is a starting point for you to develop smart contracts on the Flow Blockchain. It comes with example contracts, scripts, transactions, and tests to help you get started.

## 🔨 Getting Started

Expand Down Expand Up @@ -33,6 +33,26 @@ Inside the `cadence` folder you will find:
- `/tests` - This folder contains your Cadence tests (integration tests for your contracts, scripts, and transactions to verify they behave as expected){{ range .Tests }}
- `{{ .Name }}.cdc`{{ end }}

## Running the Existing Project

### Executing the `GetCounter` Script

To run the `GetCounter` script, use the following command:

```shell
flow scripts execute cadence/scripts/GetCounter.cdc
```

### Sending the `IncrementCounter` Transaction

To run the `IncrementCounter` transaction, use the following command:

```shell
flow transactions send cadence/transactions/IncrementCounter.cdc
```

To learn more about using the CLI, check out the [Flow CLI Documentation](https://developers.flow.com/tools/flow-cli).

## 👨‍💻 Start Developing

### Creating a New Contract
Expand Down
15 changes: 8 additions & 7 deletions internal/super/generator/templates/transaction_counter.cdc.tmpl
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import "{{ .ContractName }}"

transaction {
prepare(signer: auth(BorrowValue) &Account) {
// Borrow a reference to the {{ .ContractName }} contract's public capability
let counterRef = signer.borrow<&{{ .ContractName }}>(from: /storage/counter)
?? panic("Could not borrow reference to the counter")

// Call the increment function on the Counter contract
counterRef.increment()
prepare(acct: &Account) {
// Authorizes the transaction
}

execute {
log("Counter incremented successfully")
// Increment the counter
Counter.increment()

// Retrieve the new count and log it
let newCount = Counter.getCount()
log("New count after incrementing: ".concat(newCount.toString()))
}
}
22 changes: 21 additions & 1 deletion testing/better/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 👋 Welcome Flow Developer!

Welcome to your new Flow project. This project is a starting point for you to develop smart contracts on the Flow Blockchain. It comes with example contracts, scripts, transactions, and tests to help you get started.
This project is a starting point for you to develop smart contracts on the Flow Blockchain. It comes with example contracts, scripts, transactions, and tests to help you get started.

## 🔨 Getting started

Expand Down Expand Up @@ -38,6 +38,26 @@ Inside `cadence` folder you will find:
- `/tests` - This folder contains your Cadence tests (integration tests for your contracts, scripts, and transactions to verify they behave as expected)
- `Counter_test.cdc`

## Running the Existing Project

### Executing the `GetCounter` Script

To run the `GetCounter` script, use the following command:

```shell
flow scripts execute cadence/scripts/GetCounter.cdc
```

### Sending the `IncrementCounter` Transaction

To run the `IncrementCounter` transaction, use the following command:

```shell
flow transactions send cadence/transactions/IncrementCounter.cdc
```

To learn more about using the CLI, check out the [Flow CLI Documentation](https://developers.flow.com/tools/flow-cli).

## 👨‍💻 Start Developing

### Creating a New Contract
Expand Down

0 comments on commit 3e0a1f6

Please sign in to comment.