7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
53 lines
967 B
Go
53 lines
967 B
Go
package mtproto
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/zap"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/mt"
|
|
)
|
|
|
|
func TestConn_handleFutureSalts(t *testing.T) {
|
|
now := time.Now()
|
|
ts := int(now.Unix())
|
|
testdata := []mt.FutureSalt{
|
|
{
|
|
ValidSince: ts - 1,
|
|
ValidUntil: ts + 1,
|
|
Salt: 10,
|
|
},
|
|
{
|
|
ValidSince: ts + 1,
|
|
ValidUntil: ts + 3,
|
|
Salt: 11,
|
|
},
|
|
}
|
|
|
|
t.Run("OK", func(t *testing.T) {
|
|
a := require.New(t)
|
|
conn := Conn{log: zap.NewNop()}
|
|
buf := bin.Buffer{}
|
|
|
|
a.NoError(buf.Encode(&mt.FutureSalts{
|
|
ReqMsgID: 1,
|
|
Now: 1,
|
|
Salts: testdata,
|
|
}))
|
|
a.NoError(conn.handleFutureSalts(&buf))
|
|
|
|
salt, ok := conn.salts.Get(now)
|
|
a.Equal(int64(10), salt)
|
|
a.True(ok)
|
|
})
|
|
t.Run("Invalid", func(t *testing.T) {
|
|
conn := Conn{}
|
|
buf := bin.Buffer{}
|
|
buf.PutID(mt.FutureSaltsTypeID)
|
|
require.Error(t, conn.handleFutureSalts(&buf))
|
|
})
|
|
}
|