diff --git a/Makefile b/Makefile index c94e67b..4351ffc 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,18 @@ generate-wrappers: build $(foreach sc,$(all_sc),generate-wrapper.$(sc)) test: @go test ./tests/... +# Run all code formatters +fmts: fumpt imports + +# Reformat imports +imports: + @echo "⇒ Processing goimports check" + @goimports -w $(all_sc) tests/ + +fumpt: + @echo "⇒ Processing gofumpt check" + @gofumpt -l -w $(all_sc) tests/ + clean: find . -name '*.nef' -exec rm -rf {} \; find . -name 'config.json' -exec rm -rf {} \; diff --git a/alphabet/doc.go b/alphabet/doc.go index fc7228b..9176aaf 100644 --- a/alphabet/doc.go +++ b/alphabet/doc.go @@ -20,13 +20,12 @@ Alphabet contract does not produce notifications to process. # Contract storage scheme - | Key | Value | Description | - |--------------------|------------|-------------------------------------------------| - | `netmapScriptHash` | Hash160 | netmap contract hash | - | `proxyScriptHash` | Hash160 | proxy contract hash | - | `name` | string | assigned glagolitic letter | - | `index` | int | the index of deployed alphabet contract | - | `threshold` | int | the total number of deployed alphabet contracts | - + | Key | Value | Description | + |--------------------|------------|-------------------------------------------------| + | `netmapScriptHash` | Hash160 | netmap contract hash | + | `proxyScriptHash` | Hash160 | proxy contract hash | + | `name` | string | assigned glagolitic letter | + | `index` | int | the index of deployed alphabet contract | + | `threshold` | int | the total number of deployed alphabet contracts | */ package alphabet diff --git a/audit/doc.go b/audit/doc.go index 15d7039..56dfc00 100644 --- a/audit/doc.go +++ b/audit/doc.go @@ -21,10 +21,9 @@ Audit contract does not produce notifications to process. # Contract storage scheme - | Key | Value | Description | - |--------------------|------------|-----------------------------------------------------------| - | `netmapScriptHash` | Hash160 | netmap contract hash | - | auditID | ByteArray | serialized DataAuditResult structure | - + | Key | Value | Description | + |--------------------|------------|-----------------------------------------------------------| + | `netmapScriptHash` | Hash160 | netmap contract hash | + | auditID | ByteArray | serialized DataAuditResult structure | */ package audit diff --git a/balance/balance_contract.go b/balance/balance_contract.go index 2a9ba02..455c7c6 100644 --- a/balance/balance_contract.go +++ b/balance/balance_contract.go @@ -330,9 +330,7 @@ func (t Token) transfer(ctx storage.Context, from, to interop.Hash160, amount in // canTransfer returns the amount it can transfer. func (t Token) canTransfer(ctx storage.Context, from, to interop.Hash160, amount int, innerRing bool) (Account, bool) { - var ( - emptyAcc = Account{} - ) + emptyAcc := Account{} if !innerRing { if len(to) != interop.Hash160Len || !isUsableAddress(from) { diff --git a/balance/doc.go b/balance/doc.go index d869926..437d546 100644 --- a/balance/doc.go +++ b/balance/doc.go @@ -77,11 +77,10 @@ when FrostFS contract has transferred GAS assets back to the user. # Contract storage scheme - | Key | Value | Description | - |-----------------------|------------|----------------------------------| - | `netmapScriptHash` | Hash160 | netmap contract hash | - | `containerScriptHash` | Hash160 | container contract hash | - | circulationKey | int | the token circulation key value | - + | Key | Value | Description | + |-----------------------|------------|----------------------------------| + | `netmapScriptHash` | Hash160 | netmap contract hash | + | `containerScriptHash` | Hash160 | container contract hash | + | circulationKey | int | the token circulation key value | */ package balance diff --git a/container/container_contract.go b/container/container_contract.go index cee3d36..2ee2bea 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -82,9 +82,7 @@ const ( defaultTTL = 3600 // 1 hour ) -var ( - eACLPrefix = []byte("eACL") -) +var eACLPrefix = []byte("eACL") // OnNEP11Payment is needed for registration with contract as the owner to work. func OnNEP11Payment(a interop.Hash160, b int, c []byte, d interface{}) { @@ -187,7 +185,8 @@ func Put(container []byte, signature interop.Signature, publicKey interop.Public // Note that zone must exist. func PutNamed(container []byte, signature interop.Signature, publicKey interop.PublicKey, token []byte, - name, zone string) { + name, zone string, +) { ctx := storage.GetContext() ownerID := ownerFromBinaryContainer(container) diff --git a/container/doc.go b/container/doc.go index 7cddfc8..20dcb6e 100644 --- a/container/doc.go +++ b/container/doc.go @@ -26,19 +26,17 @@ it in Container contract. # Contract storage scheme - | Key | Value | Description | - |-----------------------------------------------------------------------------------------------------| - | `netmapScriptHash` | Hash160 | netmap contract hash | - | `balanceScriptHash` | Hash160 | balance contract hash | - | `identityScriptHash` | Hash160 | frostfsID contract hash | - | `nnsContractKey` | Hash160 | nns contract hash | - | `nnsRoot` | string | default value for domain zone | - | `cnr` + epoch + containerID + publicKeyHash[:10] | ByteArray | estimated container size | - | `est` + containerID + publicKeyHash | ByteArray | serialized epochs array | - | `o` + ownerID + containerID | ByteArray | container ID | - | `x` + containerID | ByteArray | serialized container struct | - | `nnsHasAlias` + containerID | string | domain name | - - + | Key | Value | Description | + |-----------------------------------------------------------------------------------------------------| + | `netmapScriptHash` | Hash160 | netmap contract hash | + | `balanceScriptHash` | Hash160 | balance contract hash | + | `identityScriptHash` | Hash160 | frostfsID contract hash | + | `nnsContractKey` | Hash160 | nns contract hash | + | `nnsRoot` | string | default value for domain zone | + | `cnr` + epoch + containerID + publicKeyHash[:10] | ByteArray | estimated container size | + | `est` + containerID + publicKeyHash | ByteArray | serialized epochs array | + | `o` + ownerID + containerID | ByteArray | container ID | + | `x` + containerID | ByteArray | serialized container struct | + | `nnsHasAlias` + containerID | string | domain name | */ package container diff --git a/frostfs/doc.go b/frostfs/doc.go index 35b1e0e..ec22bd8 100644 --- a/frostfs/doc.go +++ b/frostfs/doc.go @@ -83,12 +83,10 @@ FrostFS network configuration value. # Contract storage scheme - | Key | Value | Description | - |-----------------------------------------------------------------------------| - | `processingScriptHash` | Hash160 | processing contract hash | - | `candidates` + candidateKey | ByteArray | it flags inner ring candidate | - | `config` + postfix | ByteArray | serialized config data | - - + | Key | Value | Description | + |-----------------------------------------------------------------------------| + | `processingScriptHash` | Hash160 | processing contract hash | + | `candidates` + candidateKey | ByteArray | it flags inner ring candidate | + | `config` + postfix | ByteArray | serialized config data | */ package frostfs diff --git a/frostfs/frostfs_contract.go b/frostfs/frostfs_contract.go index f005794..765366a 100644 --- a/frostfs/frostfs_contract.go +++ b/frostfs/frostfs_contract.go @@ -38,9 +38,7 @@ const ( ignoreDepositNotification = "\x57\x0b" ) -var ( - configPrefix = []byte("config") -) +var configPrefix = []byte("config") // _deploy sets up initial alphabet node keys. func _deploy(data interface{}, isUpdate bool) { diff --git a/frostfsid/doc.go b/frostfsid/doc.go index 1f6a836..9efa8f4 100644 --- a/frostfsid/doc.go +++ b/frostfsid/doc.go @@ -19,11 +19,10 @@ FrostFSID contract does not produce notifications to process. # Contract storage scheme - | Key | Value | Description | - |-----------------------------|------------|----------------------------------| - | `processingScriptHash` | Hash160 | netmap contract hash | - | `containerScriptHash` | Hash160 | container contract hash | - | `o` + ownerID + publicKey | ByteArray | it flags owner's public key | - + | Key | Value | Description | + |-----------------------------|------------|----------------------------------| + | `processingScriptHash` | Hash160 | netmap contract hash | + | `containerScriptHash` | Hash160 | container contract hash | + | `o` + ownerID + publicKey | ByteArray | it flags owner's public key | */ package frostfsid diff --git a/netmap/doc.go b/netmap/doc.go index 88233c1..9df6c3c 100644 --- a/netmap/doc.go +++ b/netmap/doc.go @@ -32,15 +32,14 @@ in the network by invoking NewEpoch method. # Contract storage scheme - | Key | Value | Description | - |-----------------------------|------------|-----------------------------------| - | `snapshotCount` | int | snapshot count | - | `snapshotEpoch` | int | snapshot epoch | - | `snapshotBlock` | int | snapshot block | - | `snapshot_` + snapshotNum | ByteArray | serialized '[]Node' array | - | `snapshotCurrent` | int | current snapshot | - | `balanceScriptHash` | Hash160 | balance contract hash | - | `containerScriptHash` | Hash160 | container contract hash | - + | Key | Value | Description | + |-----------------------------|------------|-----------------------------------| + | `snapshotCount` | int | snapshot count | + | `snapshotEpoch` | int | snapshot epoch | + | `snapshotBlock` | int | snapshot block | + | `snapshot_` + snapshotNum | ByteArray | serialized '[]Node' array | + | `snapshotCurrent` | int | current snapshot | + | `balanceScriptHash` | Hash160 | balance contract hash | + | `containerScriptHash` | Hash160 | container contract hash | */ package netmap diff --git a/netmap/netmap_contract.go b/netmap/netmap_contract.go index df8a87a..2a46a6e 100644 --- a/netmap/netmap_contract.go +++ b/netmap/netmap_contract.go @@ -69,7 +69,7 @@ var ( func _deploy(data interface{}, isUpdate bool) { ctx := storage.GetContext() - var args = data.(struct { + args := data.(struct { addrBalance interop.Hash160 addrContainer interop.Hash160 keys []interop.PublicKey diff --git a/processing/doc.go b/processing/doc.go index 586b967..fa2d4f0 100644 --- a/processing/doc.go +++ b/processing/doc.go @@ -21,9 +21,8 @@ Processing contract does not produce notifications to process. # Contract storage scheme - | Key | Value | Description | - |-----------------------------|------------|----------------------------------| - | `frostfsScriptHash` | Hash160 | frostFS contract hash | - + | Key | Value | Description | + |-----------------------------|------------|----------------------------------| + | `frostfsScriptHash` | Hash160 | frostFS contract hash | */ package processing diff --git a/proxy/doc.go b/proxy/doc.go index c138cb9..2a261cc 100644 --- a/proxy/doc.go +++ b/proxy/doc.go @@ -21,6 +21,5 @@ Proxy contract does not produce notifications to process. # Contract storage scheme Proxy contract does not use storage - */ package proxy diff --git a/reputation/doc.go b/reputation/doc.go index 891e084..094f6cb 100644 --- a/reputation/doc.go +++ b/reputation/doc.go @@ -16,10 +16,9 @@ Reputation contract does not produce notifications to process. # Contract storage scheme - | Key | Value | Description | - |-----------------------------|------------|-----------------------------------| - | `c` + epoch + peerID | int | peer reputation count | - | `r` + count | ByteArray | serialized DataAuditResult struct | - + | Key | Value | Description | + |-----------------------------|------------|-----------------------------------| + | `c` + epoch + peerID | int | peer reputation count | + | `r` + count | ByteArray | serialized DataAuditResult struct | */ package reputation diff --git a/tests/container_test.go b/tests/container_test.go index 90af2a6..25b99e1 100644 --- a/tests/container_test.go +++ b/tests/container_test.go @@ -24,8 +24,8 @@ import ( const containerPath = "../container" const ( - containerFee = 0_0100_0000 - containerAliasFee = 0_0050_0000 + containerFee = 0o_0100_0000 + containerAliasFee = 0o_0050_0000 ) func deployContainerContract(t *testing.T, e *neotest.Executor, addrNetmap, addrBalance, addrNNS util.Uint160) util.Uint160 { @@ -163,7 +163,6 @@ func checkContainerList(t *testing.T, c *neotest.ContractInvoker, expected [][]b } require.ElementsMatch(t, expected, actual) }) - } func TestContainerPut(t *testing.T) { @@ -228,7 +227,8 @@ func TestContainerPut(t *testing.T) { c2.Invoke(t, stackitem.Null{}, "putNamed", putArgs...) expected = stackitem.NewArray([]stackitem.Item{ - stackitem.NewByteArray([]byte(base58.Encode(cnt.id[:])))}) + stackitem.NewByteArray([]byte(base58.Encode(cnt.id[:]))), + }) cNNS.Invoke(t, expected, "resolve", "domain.cdn", int64(nns.TXT)) }) }) diff --git a/tests/frostfs_test.go b/tests/frostfs_test.go index 631c659..6690c2b 100644 --- a/tests/frostfs_test.go +++ b/tests/frostfs_test.go @@ -21,7 +21,8 @@ import ( const frostfsPath = "../frostfs" func deployFrostFSContract(t *testing.T, e *neotest.Executor, addrProc util.Uint160, - pubs keys.PublicKeys, config ...interface{}) util.Uint160 { + pubs keys.PublicKeys, config ...interface{}, +) util.Uint160 { args := make([]interface{}, 3) args[0] = addrProc diff --git a/tests/nns_test.go b/tests/nns_test.go index e58a24f..b64d84d 100644 --- a/tests/nns_test.go +++ b/tests/nns_test.go @@ -115,7 +115,8 @@ func TestNNSRegister(t *testing.T) { expected = stackitem.NewArray([]stackitem.Item{ stackitem.NewByteArray([]byte("first TXT record")), - stackitem.NewByteArray([]byte("second TXT record"))}) + stackitem.NewByteArray([]byte("second TXT record")), + }) c.Invoke(t, expected, "getRecords", "testdomain.com", int64(nns.TXT)) cAcc.Invoke(t, stackitem.Null{}, "setRecord", @@ -123,7 +124,8 @@ func TestNNSRegister(t *testing.T) { expected = stackitem.NewArray([]stackitem.Item{ stackitem.NewByteArray([]byte("replaced first")), - stackitem.NewByteArray([]byte("second TXT record"))}) + stackitem.NewByteArray([]byte("second TXT record")), + }) c.Invoke(t, expected, "getRecords", "testdomain.com", int64(nns.TXT)) } @@ -185,7 +187,8 @@ func TestNNSRegisterMulti(t *testing.T) { c2.Invoke(t, stackitem.Null{}, "addRecord", "cdn.mainnet.fs.neo.com", int64(nns.A), "166.15.14.13") result := stackitem.NewArray([]stackitem.Item{ - stackitem.NewByteArray([]byte("166.15.14.13"))}) + stackitem.NewByteArray([]byte("166.15.14.13")), + }) c2.Invoke(t, result, "resolve", "cdn.mainnet.fs.neo.com", int64(nns.A)) } @@ -262,7 +265,8 @@ func TestExpiration(t *testing.T) { checkProperties := func(t *testing.T, expiration uint64) { expected := stackitem.NewMapWithValue([]stackitem.MapElement{ {Key: stackitem.Make("name"), Value: stackitem.Make("testdomain.com")}, - {Key: stackitem.Make("expiration"), Value: stackitem.Make(expiration)}}) + {Key: stackitem.Make("expiration"), Value: stackitem.Make(expiration)}, + }) s, err := c.TestInvoke(t, "properties", "testdomain.com") require.NoError(t, err) require.Equal(t, expected.Value(), s.Top().Item().Value()) @@ -351,7 +355,8 @@ func TestNNSRenew(t *testing.T) { c1.Invoke(t, ts, "renew", "testdomain.com") expected := stackitem.NewMapWithValue([]stackitem.MapElement{ {Key: stackitem.Make("name"), Value: stackitem.Make("testdomain.com")}, - {Key: stackitem.Make("expiration"), Value: stackitem.Make(ts)}}) + {Key: stackitem.Make("expiration"), Value: stackitem.Make(ts)}, + }) cAcc.Invoke(t, expected, "properties", "testdomain.com") }