Skip to content

Commit

Permalink
Add new events + types (#111)
Browse files Browse the repository at this point in the history
* Revert "Add ExtrinsicSignatureV5 (#68)"

This reverts commit 461cf42.

* Added new events + types

* Add tests

* Remove fmt

* typo
  • Loading branch information
mikiquantum committed Dec 15, 2020
1 parent 84ed6a9 commit 03102b8
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 21 deletions.
5 changes: 5 additions & 0 deletions hash/blake2b.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ func NewBlake2b128(k []byte) (hash.Hash, error) {
func NewBlake2b256(k []byte) (hash.Hash, error) {
return blake2b.New256(k)
}

// NewBlake2b512 returns blake2b-512 hasher
func NewBlake2b512(k []byte) (hash.Hash, error) {
return blake2b.New512(k)
}
16 changes: 16 additions & 0 deletions hash/blake2b_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,19 @@ func TestBlake2_128Concat(t *testing.T) {
h.Reset()
assert.Equal(t, 16, h.Size())
}

func TestBlake2b_512(t *testing.T) {
h, err := NewBlake2b512(nil)
assert.NoError(t, err)
n, err := h.Write([]byte("abc"))
assert.NoError(t, err)
assert.Equal(t, 3, n)
assert.Equal(t, []byte{
0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0xd, 0x6a, 0x27, 0x97, 0xb6, 0x9f, 0x12, 0xf6, 0xe9, 0x4c, 0x21, 0x2f,
0x14, 0x68, 0x5a, 0xc4, 0xb7, 0x4b, 0x12, 0xbb, 0x6f, 0xdb, 0xff, 0xa2, 0xd1, 0x7d, 0x87, 0xc5, 0x39, 0x2a, 0xab,
0x79, 0x2d, 0xc2, 0x52, 0xd5, 0xde, 0x45, 0x33, 0xcc, 0x95, 0x18, 0xd3, 0x8a, 0xa8, 0xdb, 0xf1, 0x92, 0x5a, 0xb9,
0x23, 0x86, 0xed, 0xd4, 0x0, 0x99, 0x23,
}, h.Sum(nil))
assert.Equal(t, 128, h.BlockSize())
assert.Equal(t, 64, h.Size())
}
7 changes: 3 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func Example_makeASimpleTransfer() {
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
SpecVersion: rv.SpecVersion,
Tip: types.NewUCompactFromUInt(0),
TransactionVersion: rv.TransactionVersion,
}

// Sign the transaction using Alice's default account
Expand Down Expand Up @@ -375,7 +376,7 @@ func Example_displaySystemEvents() {
fmt.Printf("\tSystem:ExtrinsicSuccess:: (phase=%#v)\n", e.Phase)
}
for _, e := range events.System_ExtrinsicFailed {
fmt.Printf("\tSystem:ErtrinsicFailed:: (phase=%#v)\n", e.Phase)
fmt.Printf("\tSystem:ExtrinsicFailed:: (phase=%#v)\n", e.Phase)
fmt.Printf("\t\t%v\n", e.DispatchError)
}
for _, e := range events.System_CodeUpdated {
Expand Down Expand Up @@ -422,9 +423,6 @@ func Example_transactionWithEvents() {

// Create the extrinsic
ext := types.NewExtrinsic(c)
if err != nil {
panic(err)
}

genesisHash, err := api.RPC.Chain.GetBlockHash(0)
if err != nil {
Expand Down Expand Up @@ -457,6 +455,7 @@ func Example_transactionWithEvents() {
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
SpecVersion: rv.SpecVersion,
Tip: types.NewUCompactFromUInt(0),
TransactionVersion: rv.TransactionVersion,
}

fmt.Printf("Sending %v from %#x to %#x with nonce %v", amount, signature.TestKeyringPairAlice.PublicKey, bob.AsAccountID, nonce)
Expand Down
2 changes: 1 addition & 1 deletion teste2e/author_submit_and_watch_extrinsic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestAuthor_SubmitAndWatchExtrinsic(t *testing.T) {
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
SpecVersion: rv.SpecVersion,
Tip: types.NewUCompactFromUInt(0),
TransactionVersion: 1,
TransactionVersion: rv.TransactionVersion,
}

err = ext.Sign(from, o)
Expand Down
2 changes: 1 addition & 1 deletion teste2e/author_submit_extrinsic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestChain_SubmitExtrinsic(t *testing.T) {
Nonce: types.NewUCompactFromUInt(uint64(nonce + i)),
SpecVersion: rv.SpecVersion,
Tip: types.NewUCompactFromUInt(0),
TransactionVersion: 1,
TransactionVersion: rv.TransactionVersion,
}

extI := ext
Expand Down
17 changes: 17 additions & 0 deletions types/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,26 @@ import (
"encoding/binary"
"testing"

"github.com/btcsuite/btcutil/base58"
"github.com/centrifuge/go-substrate-rpc-client/hash"
. "github.com/centrifuge/go-substrate-rpc-client/types"
"github.com/stretchr/testify/assert"
)

func TestChecksum(t *testing.T) {
//verify checksum from ss58
contextPrefix := []byte("SS58PRE")
ss58d := base58.Decode("4ecQzsMCwbJXu6Cad597T7gZx1MTZWQi8jZZC2DmsQq72knj")
assert.Equal(t, uint8(36), ss58d[0]) // Centrifuge network version check
noSum := ss58d[:len(ss58d)-2]
all := append(contextPrefix, noSum...)
checksum, err := hash.NewBlake2b512(nil)
assert.NoError(t, err)
checksum.Write(all)
res := checksum.Sum(nil)
assert.Equal(t, ss58d[len(ss58d)-2:], res[:2]) // Verified checksum
}

func TestAddress_EncodeDecode(t *testing.T) {
assertRoundtrip(t, NewAddressFromAccountID([]byte{128, 42}))
assertRoundtrip(t, NewAddressFromAccountIndex(421))
Expand Down
24 changes: 20 additions & 4 deletions types/event_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type EventRecords struct {
Democracy_PreimageMissing []EventDemocracyPreimageMissing //nolint:stylecheck,golint
Democracy_PreimageReaped []EventDemocracyPreimageReaped //nolint:stylecheck,golint
Democracy_Unlocked []EventDemocracyUnlocked //nolint:stylecheck,golint
Democracy_Blacklisted []EventDemocracyBlacklisted //nolint:stylecheck,golint
Council_Proposed []EventCollectiveProposed //nolint:stylecheck,golint
Council_Voted []EventCollectiveProposed //nolint:stylecheck,golint
Council_Approved []EventCollectiveApproved //nolint:stylecheck,golint
Expand All @@ -125,8 +126,15 @@ type EventRecords struct {
TechnicalCommittee_Executed []EventTechnicalCommitteeExecuted //nolint:stylecheck,golint
TechnicalCommittee_MemberExecuted []EventTechnicalCommitteeMemberExecuted //nolint:stylecheck,golint
TechnicalCommittee_Closed []EventTechnicalCommitteeClosed //nolint:stylecheck,golint
TechnicalMembership_MemberAdded []EventTechnicalMembershipMemberAdded //nolint:stylecheck,golint
TechnicalMembership_MemberRemoved []EventTechnicalMembershipMemberRemoved //nolint:stylecheck,golint
TechnicalMembership_MembersSwapped []EventTechnicalMembershipMembersSwapped //nolint:stylecheck,golint
TechnicalMembership_MembersReset []EventTechnicalMembershipMembersReset //nolint:stylecheck,golint
TechnicalMembership_KeyChanged []EventTechnicalMembershipKeyChanged //nolint:stylecheck,golint
TechnicalMembership_Dummy []EventTechnicalMembershipDummy //nolint:stylecheck,golint
Elections_NewTerm []EventElectionsNewTerm //nolint:stylecheck,golint
Elections_EmptyTerm []EventElectionsEmptyTerm //nolint:stylecheck,golint
Elections_ElectionError []EventElectionsElectionError //nolint:stylecheck,golint
Elections_MemberKicked []EventElectionsMemberKicked //nolint:stylecheck,golint
Elections_MemberRenounced []EventElectionsMemberRenounced //nolint:stylecheck,golint
Elections_VoterReported []EventElectionsVoterReported //nolint:stylecheck,golint
Expand Down Expand Up @@ -169,6 +177,7 @@ type EventRecords struct {
Scheduler_Dispatched []EventSchedulerDispatched //nolint:stylecheck,golint
Proxy_ProxyExecuted []EventProxyProxyExecuted //nolint:stylecheck,golint
Proxy_AnonymousCreated []EventProxyAnonymousCreated //nolint:stylecheck,golint
Proxy_Announced []EventProxyAnnounced //nolint:stylecheck,golint
Sudo_Sudid []EventSudoSudid //nolint:stylecheck,golint
Sudo_KeyChanged []EventSudoKeyChanged //nolint:stylecheck,golint
Sudo_SudoAsDone []EventSudoAsDone //nolint:stylecheck,golint
Expand All @@ -183,6 +192,13 @@ type EventRecords struct {
Treasury_TipClosing []EventTreasuryTipClosing //nolint:stylecheck,golint
Treasury_TipClosed []EventTreasuryTipClosed //nolint:stylecheck,golint
Treasury_TipRetracted []EventTreasuryTipRetracted //nolint:stylecheck,golint
Treasury_BountyProposed []EventTreasuryBountyProposed //nolint:stylecheck,golint
Treasury_BountyRejected []EventTreasuryBountyRejected //nolint:stylecheck,golint
Treasury_BountyBecameActive []EventTreasuryBountyBecameActive //nolint:stylecheck,golint
Treasury_BountyAwarded []EventTreasuryBountyAwarded //nolint:stylecheck,golint
Treasury_BountyClaimed []EventTreasuryBountyClaimed //nolint:stylecheck,golint
Treasury_BountyCanceled []EventTreasuryBountyCanceled //nolint:stylecheck,golint
Treasury_BountyExtended []EventTreasuryBountyExtended //nolint:stylecheck,golint
Contracts_Instantiated []EventContractsInstantiated //nolint:stylecheck,golint
Contracts_Evicted []EventContractsEvicted //nolint:stylecheck,golint
Contracts_Restored []EventContractsRestored //nolint:stylecheck,golint
Expand All @@ -191,10 +207,10 @@ type EventRecords struct {
Contracts_ContractExecution []EventContractsContractExecution //nolint:stylecheck,golint
Utility_BatchInterrupted []EventUtilityBatchInterrupted //nolint:stylecheck,golint
Utility_BatchCompleted []EventUtilityBatchCompleted //nolint:stylecheck,golint
Multisig_New []EventMultisigNewMultisig //nolint:stylecheck,golint
Multisig_Approval []EventMultisigApproval //nolint:stylecheck,golint
Multisig_Executed []EventMultisigExecuted //nolint:stylecheck,golint
Multisig_Cancelled []EventMultisigCancelled //nolint:stylecheck,golint
Multisig_NewMultisig []EventMultisigNewMultisig //nolint:stylecheck,golint
Multisig_MultisigApproval []EventMultisigApproval //nolint:stylecheck,golint
Multisig_MultisigExecuted []EventMultisigExecuted //nolint:stylecheck,golint
Multisig_MultisigCancelled []EventMultisigCancelled //nolint:stylecheck,golint
}

// DecodeEventRecords decodes the events records from an EventRecordRaw into a target t using the given Metadata m
Expand Down
Loading

0 comments on commit 03102b8

Please sign in to comment.