MCPcopy
hub / github.com/canopy-network/canopy / TestSign

Function TestSign

lib/tx_test.go:227–260  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

225}
226
227func TestSign(t *testing.T) {
228 // pre-define a private key
229 pk, err := crypto.NewBLS12381PrivateKey()
230 require.NoError(t, err)
231 // pre-define a test message
232 sig := &Signature{
233 PublicKey: newTestPublicKeyBytes(t),
234 Signature: newTestPublicKeyBytes(t),
235 }
236 // pre-define an any for testing
237 a, e := NewAny(sig)
238 require.NoError(t, e)
239 // pre-define a transaction
240 tx := &Transaction{
241 MessageType: testMessageName,
242 Msg: a,
243 Signature: sig,
244 Time: uint64(time.Now().UnixMicro()),
245 Fee: 1,
246 Memo: "memo",
247 }
248 // get sign bytes
249 bz, err := tx.GetSignBytes()
250 require.NoError(t, err)
251 // calculate expected
252 expected := &Signature{
253 PublicKey: pk.PublicKey().Bytes(),
254 Signature: pk.Sign(bz),
255 }
256 // execute function call
257 require.NoError(t, tx.Sign(pk))
258 // compare got vs expected
259 require.EqualExportedValues(t, expected, tx.Signature)
260}
261
262func TestTransactionJSON(t *testing.T) {
263 // pre-define a test message

Callers

nothing calls this directly

Calls 8

GetSignBytesMethod · 0.95
PublicKeyMethod · 0.95
SignMethod · 0.95
SignMethod · 0.95
NewBLS12381PrivateKeyFunction · 0.92
NewAnyFunction · 0.85
newTestPublicKeyBytesFunction · 0.70
BytesMethod · 0.65

Tested by

no test coverage detected