-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from onflow/c1-migration
C1 migration
- Loading branch information
Showing
12 changed files
with
320 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Run Cadence Contract Compilation, Deployment, Transaction Execution, and Lint | ||
on: push | ||
|
||
jobs: | ||
run-cadence-lint: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: 'true' | ||
|
||
- name: Install Flow CLI | ||
run: | | ||
brew update | ||
brew install flow-cli | ||
- name: Initialize Flow | ||
run: | | ||
if [ ! -f flow.json ]; then | ||
echo "Initializing Flow project..." | ||
flow init | ||
else | ||
echo "Flow project already initialized." | ||
fi | ||
flow dependencies install | ||
- name: Start Flow Emulator | ||
run: | | ||
echo "Starting Flow emulator in the background..." | ||
nohup flow emulator start > emulator.log 2>&1 & | ||
sleep 5 # Wait for the emulator to start | ||
flow project deploy --network=emulator # Deploy the recipe contracts indicated in flow.json | ||
- name: Run All Transactions | ||
run: | | ||
echo "Running all transactions in the transactions folder..." | ||
for file in ./cadence/transactions/*.cdc; do | ||
echo "Running transaction: $file" | ||
TRANSACTION_OUTPUT=$(flow transactions send "$file" --signer emulator-account) | ||
echo "$TRANSACTION_OUTPUT" | ||
if echo "$TRANSACTION_OUTPUT" | grep -q "Transaction Error"; then | ||
echo "Transaction Error detected in $file, failing the action..." | ||
exit 1 | ||
fi | ||
done | ||
- name: Run Cadence Lint | ||
run: | | ||
echo "Running Cadence linter on .cdc files in the current repository" | ||
flow cadence lint ./cadence/**/*.cdc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Run Cadence Tests | ||
on: push | ||
|
||
jobs: | ||
run-cadence-tests: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: 'true' | ||
|
||
- name: Install Flow CLI | ||
run: | | ||
brew update | ||
brew install flow-cli | ||
- name: Initialize Flow | ||
run: | | ||
if [ ! -f flow.json ]; then | ||
echo "Initializing Flow project..." | ||
flow init | ||
else | ||
echo "Flow project already initialized." | ||
fi | ||
- name: Run Cadence Tests | ||
run: | | ||
if test -f "cadence/tests.cdc"; then | ||
echo "Running Cadence tests in the current repository" | ||
flow test cadence/tests.cdc | ||
else | ||
echo "No Cadence tests found. Skipping tests." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.DS_Store | ||
.DS_Store | ||
/imports/ | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./cadence/transactions/mint_moment.cdc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import "TopShot" | ||
|
||
transaction { | ||
let admin: &TopShot.Admin | ||
let borrowedSet: &TopShot.Set | ||
let receiverRef: &{TopShot.MomentCollectionPublic} | ||
|
||
prepare(acct: auth(Storage, Capabilities) &Account) { | ||
// Issue a capability for the admin resource and publish it for borrowing | ||
let adminCap = acct.capabilities.storage.issue<&TopShot.Admin>(/storage/TopShotAdmin) | ||
acct.capabilities.publish(adminCap, at: /public/TopShotAdminCap) | ||
|
||
// Borrow the admin resource using the published capability | ||
self.admin = acct.capabilities.borrow<&TopShot.Admin>(/public/TopShotAdminCap) | ||
?? panic("Cannot borrow admin resource from storage") | ||
|
||
// Ensure the Set resource exists | ||
if acct.storage.borrow<&TopShot.Set>(from: /storage/TopShotSet) == nil { | ||
let newSet = self.admin.createSet(name: "test_set") | ||
acct.storage.save(newSet, to: /storage/TopShotSet) | ||
} | ||
|
||
// Borrow the specified Set from the admin | ||
self.borrowedSet = self.admin.borrowSet(setID: 1) | ||
|
||
// Issue a capability for the MomentCollection and publish it | ||
let momentCap = acct.capabilities.storage.issue<&{TopShot.MomentCollectionPublic}>(/storage/MomentCollection) | ||
acct.capabilities.publish(momentCap, at: /public/MomentCollectionCap) | ||
|
||
// Borrow the recipient's MomentCollectionPublic reference | ||
self.receiverRef = acct.capabilities.borrow<&{TopShot.MomentCollectionPublic}>(/public/MomentCollectionCap) | ||
?? panic("Cannot borrow the MomentCollection reference") | ||
} | ||
|
||
execute { | ||
// Create plays if they don't already exist | ||
let playIDs: [UInt32] = [1, 2, 3] | ||
for playID in playIDs { | ||
if TopShot.getPlayMetaData(playID: playID) == nil { | ||
let metadata: {String: String} = { | ||
"Player": "Player Name ".concat(playID.toString()), | ||
"Play": "Play Description ".concat(playID.toString()) | ||
} | ||
self.admin.createPlay(metadata: metadata) | ||
} | ||
} | ||
|
||
self.borrowedSet.addPlay(playID: 1) | ||
self.borrowedSet.addPlay(playID: 2) | ||
self.borrowedSet.addPlay(playID: 3) | ||
|
||
// Mint moments using the borrowed set | ||
let mintedMoments <- self.borrowedSet.batchMintMoment(playID: 1, quantity: 3) | ||
|
||
// Deposit the minted moments into the recipient's collection | ||
self.receiverRef.batchDeposit(tokens: <-mintedMoments) | ||
|
||
log("Minted and deposited moments into the recipient's collection.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0xdc07d83a937644ff362b279501b7f7a3735ac91a0f3647147acf649dda804e28 |
Oops, something went wrong.