Skip to content

Commit

Permalink
fixed authorizer types in a transaction that it is keyed to the addre…
Browse files Browse the repository at this point in the history
…ss of an authorizer
  • Loading branch information
bjartek committed Feb 28, 2024
1 parent debbac8 commit 4958357
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions npm_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type OverflowSolution struct {
Warnings []string `json:"warnings"`
}

type OverflowAuthorizers map[string][]string
type OverflowAuthorizers [][]string

// a type containing information about parameter types and orders
type OverflowDeclarationInfo struct {
Expand Down Expand Up @@ -192,7 +192,7 @@ func paramsAndAuthorizers(code []byte) (*ast.ParameterList, OverflowAuthorizers)
prepareParams := txd.Prepare.FunctionDeclaration.ParameterList
if prepareParams != nil {
for _, parg := range txd.Prepare.FunctionDeclaration.ParameterList.ParametersByIdentifier() {
name := parg.Identifier.Identifier
// name := parg.Identifier.Identifier
ta := parg.TypeAnnotation
if ta != nil {
rt, ok := ta.Type.(*ast.ReferenceType)
Expand All @@ -205,7 +205,7 @@ func paramsAndAuthorizers(code []byte) (*ast.ParameterList, OverflowAuthorizers)
entitlements = append(entitlements, entitlement.Identifier.Identifier)
}
}
authorizers[name] = entitlements
authorizers = append(authorizers, entitlements)
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions testdata/TestParseConfig/parse_and_filter.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
},
"create_nft_collection": {
Parameters: map[string]string{},
Authorizers: overflow.OverflowAuthorizers{"acct": []string{"Storage"}},
Authorizers: overflow.OverflowAuthorizers{[]string{"Storage"}},
ParameterOrder: []string{},
},
"emulatorFoo": {
Parameters: map[string]string{"test": "String"},
Authorizers: overflow.OverflowAuthorizers{"acct": []string{"BorrowValue"}},
Authorizers: overflow.OverflowAuthorizers{[]string{"BorrowValue"}},
ParameterOrder: []string{"test"},
},
"mainnetFoo": {
Parameters: map[string]string{"test": "String"},
Authorizers: overflow.OverflowAuthorizers{"acct": []string{}},
Authorizers: overflow.OverflowAuthorizers{[]string{}},
ParameterOrder: []string{"test"},
},
"mainnetaTransaction": {
Expand All @@ -35,7 +35,7 @@
"amount": "UFix64",
"recipient": "Address",
},
Authorizers: overflow.OverflowAuthorizers{"signer": []string{"BorrowValue"}},
Authorizers: overflow.OverflowAuthorizers{[]string{"BorrowValue"}},
ParameterOrder: []string{
"recipient",
"amount",
Expand All @@ -44,14 +44,14 @@
"signWithMultipleAccounts": {
Parameters: map[string]string{"test": "String"},
Authorizers: overflow.OverflowAuthorizers{
"account2": []string{},
"acct": []string{},
[]string{},
[]string{},
},
ParameterOrder: []string{"test"},
},
"testnetFoo": {
Parameters: map[string]string{"test": "String"},
Authorizers: overflow.OverflowAuthorizers{"acct": []string{"Storage"}},
Authorizers: overflow.OverflowAuthorizers{[]string{"Storage"}},
ParameterOrder: []string{"test"},
},
"zTransaction": {
Expand Down
9 changes: 6 additions & 3 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Argument struct {

type OverflowTransaction struct {
Error error
AuthorizerTypes OverflowAuthorizers
AuthorizerTypes map[string][]string
Stakeholders map[string][]string
Payer string
Id string
Expand Down Expand Up @@ -100,11 +100,14 @@ func (o *OverflowState) CreateOverflowTransaction(blockId string, transactionRes
status = fmt.Sprintf("%s failed getting imports", status)
}

authorizerTypes := map[string][]string{}

authorizers := []string{}
for _, authorizer := range transaction.Authorizers {
for i, authorizer := range transaction.Authorizers {
auth := fmt.Sprintf("0x%s", authorizer.Hex())
authorizers = append(authorizers, auth)
standardStakeholders[auth] = []string{"authorizer"}
authorizerTypes[auth] = argInfo.Authorizers[i]
}

payerRoles, ok := standardStakeholders[fmt.Sprintf("0x%s", transaction.Payer.Hex())]
Expand Down Expand Up @@ -148,7 +151,7 @@ func (o *OverflowState) CreateOverflowTransaction(blockId string, transactionRes
GasUsed: uint64(gas),
ExecutionEffort: executionEffort,
Authorizers: authorizers,
AuthorizerTypes: argInfo.Authorizers,
AuthorizerTypes: authorizerTypes,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions transaction_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestTransactionIntegration(t *testing.T) {
oTx, err := o.GetOverflowTransactionById(context.Background(), result.Transaction.ID())
require.NoError(t, err)

assert.Equal(t, []string{"BorrowValue"}, oTx.AuthorizerTypes["signer"])
assert.Equal(t, []string{"BorrowValue"}, oTx.AuthorizerTypes["0xf8d6e0586b0a20c7"])
})

t.Run("fail on missing signer", func(t *testing.T) {
Expand Down Expand Up @@ -350,7 +350,7 @@ func TestTransactionIntegration(t *testing.T) {
WithSigner("first"),
).AssertSuccess(t)

assert.Equal(t, []string{"BorrowValue", "SaveValue"}, res.DeclarationInfo.Authorizers["acct"])
assert.Equal(t, []string{"BorrowValue", "SaveValue"}, res.DeclarationInfo.Authorizers[0])
})

bytes, err := o.GetCoverageReport().MarshalJSON()
Expand Down

0 comments on commit 4958357

Please sign in to comment.