mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-14 00:18:03 -05:00
34 lines
724 B
Go
34 lines
724 B
Go
package message
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/scroll-tech/go-ethereum/common"
|
|
"github.com/scroll-tech/go-ethereum/crypto"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAuthMessageSignAndVerify(t *testing.T) {
|
|
privkey, err := crypto.GenerateKey()
|
|
assert.NoError(t, err)
|
|
|
|
authMsg := &AuthMsg{
|
|
Identity: &Identity{
|
|
Name: "testRoller",
|
|
Timestamp: uint32(time.Now().Unix()),
|
|
},
|
|
}
|
|
assert.NoError(t, authMsg.Sign(privkey))
|
|
|
|
ok, err := authMsg.Verify()
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, true, ok)
|
|
|
|
// Check public key is ok.
|
|
pub, err := authMsg.PublicKey()
|
|
assert.NoError(t, err)
|
|
pubkey := crypto.CompressPubkey(&privkey.PublicKey)
|
|
assert.Equal(t, pub, common.Bytes2Hex(pubkey))
|
|
}
|