Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.42] Fix AuthAccount creation #2932

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3231,19 +3231,30 @@ func TestRuntimeTransaction_CreateAccount(t *testing.T) {
script := []byte(`
transaction {
prepare(signer: AuthAccount) {
// Important: Perform a write which will be pending until the end of the transaction,
// but should be (temporarily) committed when the AuthAccount constructor is called
signer.save(42, to: /storage/answer)
AuthAccount(payer: signer)
}
}
`)

var events []cadence.Event

var performedWrite bool

onWrite := func(owner, key, value []byte) {
performedWrite = true
}

runtimeInterface := &testRuntimeInterface{
storage: newTestLedger(nil, nil),
storage: newTestLedger(nil, onWrite),
getSigningAccounts: func() ([]Address, error) {
return []Address{{42}}, nil
},
createAccount: func(payer Address) (address Address, err error) {
// Check that pending writes were committed before
assert.True(t, performedWrite)
return Address{42}, nil
},
emitEvent: func(event cadence.Event) error {
Expand Down
14 changes: 12 additions & 2 deletions runtime/stdlib/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
GenerateAccountID(address common.Address) (uint64, error)
}

type StorageCommitter interface {
CommitStorageTemporarily(inter *interpreter.Interpreter) error
}

type AuthAccountHandler interface {
AccountIDGenerator
BalanceProvider
Expand All @@ -77,6 +81,7 @@
}

type AccountCreator interface {
StorageCommitter
EventEmitter
AuthAccountHandler
// CreateAccount creates a new account.
Expand Down Expand Up @@ -120,6 +125,11 @@

payerAddress := payerAddressValue.ToAddress()

err := creator.CommitStorageTemporarily(inter)
if err != nil {
panic(err)

Check warning on line 130 in runtime/stdlib/account.go

View check run for this annotation

Codecov / codecov/patch

runtime/stdlib/account.go#L130

Added line #L130 was not covered by tests
}

addressValue := interpreter.NewAddressValueFromConstructor(
inter,
func() (address common.Address) {
Expand Down Expand Up @@ -383,7 +393,7 @@
}

type StorageUsedProvider interface {
CommitStorageTemporarily(inter *interpreter.Interpreter) error
StorageCommitter
// GetStorageUsed gets storage used in bytes by the address at the moment of the function call.
GetStorageUsed(address common.Address) (uint64, error)
}
Expand Down Expand Up @@ -422,7 +432,7 @@
}

type StorageCapacityProvider interface {
CommitStorageTemporarily(inter *interpreter.Interpreter) error
StorageCommitter
// GetStorageCapacity gets storage capacity in bytes on the address.
GetStorageCapacity(address common.Address) (uint64, error)
}
Expand Down
Loading