Skip to content

Conversation

@fionnachan
Copy link
Contributor

Summary

Allow setting manager, reserve, freeze, and clawback at goal asset create

Test Plan

Did not test it.
I built the binaries, ran ${GOPATH}/bin/goal node start -d ~/.algorand, used goal to create a new wallet, but I don't know how to fund the wallet to continue :(

Closes #3361

@jannotti
Copy link
Contributor

jannotti commented Jan 5, 2022

Thank you! This looks good by eye, we just need some simple tests. You could add them to test/scripts/e2e_subs/asset-misc.sh

You could do another asset create, similar to line 24, and then confirm that the various addresses were set appropriately with some grep lines similar to line 26.

To run just that test, you should be able to do ./test/scripts/e2e_client_runner.py ./test/scripts/e2e_subs/asset-misc.sh from the top of your repo. That will take care of setting up a temporary test network, funding a wallet, and then invoking that script so that it can do the things inside.

@fionnachan
Copy link
Contributor Author

Added a test for --no-manager --no-freezer --no-clawback and another test for --creator "${ACCOUNT}" --manager "${ACCOUNTB}". Let me know if you want tests for --freezer / --clawback separately.

I removed the --no-reserve flag because even when the reserve is set to empty explicitly, the reserve will be the creator anyway.

@jannotti
Copy link
Contributor

jannotti commented Jan 6, 2022

I removed the --no-reserve flag because even when the reserve is set to empty explicitly, the reserve will be the creator anyway.

This is weird. I don't think this should happen, I can't find any code in goal or algod that would do this on purpose, so I'd like to figure out if there's a bug here. What exactly did you see?

Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we figure out this reserve address thing, it looks good!

Comment on lines 70 to 71
# create asset with a manager that is different from the creator
${gcmd} asset create --creator "${ACCOUNT}" --manager "${ACCOUNTB}" --name "${ASSET_NAME}" --unitname dma --total 1000000000000 --asseturl "${ASSET_URL}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer that this sets all of the different address types, not just manager, and that it use a different address for each. That way we are testing against simple cut and paste bugs where, for example, using --freezer X actually sets the reserve address.

Comment on lines 80 to 83
if [ "$DMA_MANAGER_ADDRESS" = "$ACCOUNTB" ] \
&& [ "$DMA_RESERVE_ADDRESS" = "$ACCOUNT" ] \
&& [ "$DMA_FREEZE_ADDRESS" = "$ACCOUNT" ] \
&& [ "$DMA_CLAWBACK_ADDRESS" = "$ACCOUNT" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where I'd like to see different equality checks for each address.

Comment on lines 210 to 215
if cmd.Flags().Changed("manager") {
assetManager = accountList.getAddressByName(assetManager)
manager = assetManager
}

if cmd.Flags().Changed("no-manager") {
Copy link
Contributor

@jannotti jannotti Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it would be nice to have a check to see if both "manager" is set, and "no-manager" is true, and if so, error out. (Same for others too.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. For the flag checks, I used cmd.Flags().Changed("manager") && cmd.Flags().Changed("no-manager") instead of cmd.Flags().Changed("manager") && assetNoManager because it looks nicer with two flags on the same line.... 😬

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use the variable for the manager flag directly, so you could do something as simple as assetManager != "" && assetNoManager without any use of cmd.Flags().Changed because they both have defaults set, so you would report the error if they both differ from their default.

I prefer to use the variables directly and only use Changed if I need to distinguish between when the switch gets its default value because it was not given on the command line, vs being given on the command-line, but being the same as the default. Here, the distinction does not matter.

reserve = assetReserve
}

if cmd.Flags().Changed("no-reserve") {
Copy link
Contributor

@jannotti jannotti Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slightly simpler way to use boolean flags is to set the default to false (which you've already done), and then you don't need to use Changed(), you can just use the variable directly. See for example, how assetFrozen is used.

@jannotti
Copy link
Contributor

jannotti commented Jan 6, 2022 via email

@fionnachan
Copy link
Contributor Author

I am seeing this with --no-reserve, which I didn't expect at all either before writing the test....

+ goal -w AF4A62B9687CF6BBAB8427229BE8F2D9 asset create --creator UOTRSRYEAHIPBIAOQA6HW3OI6FCRLXABNPPANGZ7WJJN2HTTTKKJAH3OII --no-manager --no-reserve --no-freezer --no-clawback --name 'Birlot : décollage vs. ࠶🦪' --unitname iamisc --total 1000000000000 --asseturl /ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Verifiable_random_function.html
Issued transaction from account UOTRSRYEAHIPBIAOQA6HW3OI6FCRLXABNPPANGZ7WJJN2HTTTKKJAH3OII, txid GCM66CSDDU36KB224LVIC7WU5LWNTYXLLSVZO7UYTULJQ6DIIVUQ (fee 1000)
Transaction GCM66CSDDU36KB224LVIC7WU5LWNTYXLLSVZO7UYTULJQ6DIIVUQ still pending as of round 20
Transaction GCM66CSDDU36KB224LVIC7WU5LWNTYXLLSVZO7UYTULJQ6DIIVUQ still pending as of round 21
Transaction GCM66CSDDU36KB224LVIC7WU5LWNTYXLLSVZO7UYTULJQ6DIIVUQ committed in round 22
Created asset with asset index 11
++ goal -w AF4A62B9687CF6BBAB8427229BE8F2D9 asset info --creator UOTRSRYEAHIPBIAOQA6HW3OI6FCRLXABNPPANGZ7WJJN2HTTTKKJAH3OII --unitname iamisc
++ grep 'Asset ID'
++ awk '{ print $3 }'
+ IMMUTABLE_ASSET_ID=11
++ goal -w AF4A62B9687CF6BBAB8427229BE8F2D9 asset info --assetid 11
++ grep 'Manager address'
++ awk '{ print $3 }'
+ MANAGER_ADDRESS=
++ goal -w AF4A62B9687CF6BBAB8427229BE8F2D9 asset info --assetid 11
++ grep 'Reserve address'
++ awk '{ print $3 }'
+ RESERVE_ADDRESS=UOTRSRYEAHIPBIAOQA6HW3OI6FCRLXABNPPANGZ7WJJN2HTTTKKJAH3OII
++ goal -w AF4A62B9687CF6BBAB8427229BE8F2D9 asset info --assetid 11
++ grep 'Freeze address'
++ awk '{ print $3 }'
+ FREEZE_ADDRESS=
++ goal -w AF4A62B9687CF6BBAB8427229BE8F2D9 asset info --assetid 11
++ grep 'Clawback address'
++ awk '{ print $3 }'
+ CLAWBACK_ADDRESS=
+ '[' '' = '' ']'
+ '[' UOTRSRYEAHIPBIAOQA6HW3OI6FCRLXABNPPANGZ7WJJN2HTTTKKJAH3OII = '' ']'
+ date '+asset-misc immutable asset info error %Y%m%d_%H%M%S'
asset-misc immutable asset info error 20220106_174132
+ exit 1
20220106_174132 :460 ERRORS after 93.727515 seconds: '/workspaces/go-algorand/test/scripts/e2e_subs/asset-misc.sh failed'
20220106_174132 :463 statuses-json: [{"script": "/workspaces/go-algorand/test/scripts/e2e_subs/asset-misc.sh", "ok": false, "seconds": 88.35015201568604}]
20220106_174132 :329 stop network in /tmp/tmp4nbvmh2a/net
20220106_174133 :338 stop kmd in /tmp/tmp4nbvmh2a/net/Node
20220106_174133 :351 delete network in /tmp/tmp4nbvmh2a/net

@fionnachan
Copy link
Contributor Author

fionnachan commented Jan 6, 2022

oh look....

reserveEmpty := false
if params.ReserveAddr == "" {
reserveEmpty = true
params.ReserveAddr = params.Creator
}

if reserveEmpty {
fmt.Printf("Reserve address: %s (Empty. Defaulting to creator)\n", params.ReserveAddr)
} else {
fmt.Printf("Reserve address: %s\n", params.ReserveAddr)
}

@jannotti
Copy link
Contributor

jannotti commented Jan 6, 2022

oh look....

reserveEmpty := false
if params.ReserveAddr == "" {
reserveEmpty = true
params.ReserveAddr = params.Creator
}

if reserveEmpty {
fmt.Printf("Reserve address: %s (Empty. Defaulting to creator)\n", params.ReserveAddr)
} else {
fmt.Printf("Reserve address: %s\n", params.ReserveAddr)
}

Ok, good find. This is only what goal reports and doesn't describe the actual value on-chain. To me, that means you should still support --no-reserve which sets the value on chain to the zero value, but it is very hard to test with goal since goal lies about the value.

@jannotti
Copy link
Contributor

jannotti commented Jan 6, 2022

Oh, for testing the --no-reserve, you can actually check if the goal output contains Empty. Defaulting to creator

jannotti
jannotti previously approved these changes Jan 7, 2022
Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, pending CI checks. Thanks again!

@algojack algojack changed the base branch from master to temp-branch January 7, 2022 21:20
@algojack algojack changed the base branch from temp-branch to master January 7, 2022 21:33
@algojack algojack dismissed jannotti’s stale review January 7, 2022 21:33

The base branch was changed.

@algojack algojack changed the base branch from master to temp-branch January 7, 2022 22:20
@algojack
Copy link
Contributor

algojack commented Jan 7, 2022

merging this to a temp branch to kick off CI correctly. Thanks again for your contribution.

@jannotti
Copy link
Contributor

This was merged as #3398 because we had a little CI hiccup. Thanks again.

@fionnachan
Copy link
Contributor Author

You're welcome~

@fionnachan fionnachan deleted the goal-asset-create-support-config branch January 10, 2022 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

goal asset create - support manager, reserve, freeze, and clawback

3 participants